Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
Implement React Native example in code
Browse files Browse the repository at this point in the history
  • Loading branch information
dilan-dio4 committed Jun 2, 2021
1 parent b2ab43b commit 79dc44f
Show file tree
Hide file tree
Showing 59 changed files with 9,705 additions and 0 deletions.
6 changes: 6 additions & 0 deletions native-example/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

[android]
target = Google Inc.:Google APIs:23

[maven_repositories]
central = https://repo1.maven.org/maven2
54 changes: 54 additions & 0 deletions native-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore
!debug.keystore

# Bundle artifacts
*.jsbundle

# CocoaPods
/ios/Pods/

# Expo
.expo/
web-build/
87 changes: 87 additions & 0 deletions native-example/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* eslint-disable operator-linebreak */
import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View, TextInput, Button } from 'react-native';
import { useEasybase, EasybaseProvider } from 'easybase-react';
import ebconfig from './ebconfig';

function Account() {
const [userVal, setUserVal] = useState("");
const [passVal, setPassVal] = useState("");

const { signIn, signUp } = useEasybase();

const clearInputs = () => {
setUserVal("");
setPassVal("");
}

const handleSignInPress = async () => {
await signIn(userVal, passVal);
clearInputs();
}

const handleSignUpPress = async () => {
const res = await signUp(userVal, passVal, {
created_at: new Date().toString
});
if (res.success) {
await signIn(userVal, passVal);
}
clearInputs();
}

return (
<View style={styles.container}>
<Text style={styles.title}>Welcome to React-flix!</Text>
<TextInput value={userVal} onChangeText={e => setUserVal(e)} style={styles.accountInput} placeholder="Username" />
<TextInput value={passVal} onChangeText={e => setPassVal(e)} style={styles.accountInput} placeholder="Password"/>
<View style={{ display: "flex", flexDirection: "row", marginTop: 30 }}>
<Button title="Sign In" onPress={handleSignInPress} />
<Button title="Sign Up" onPress={handleSignUpPress} />
</View>
</View>
)
}

function Router() {
const { isUserSignedIn } = useEasybase();

return (
isUserSignedIn() ?
<Text>Congrats! You're signed in.</Text>
:
<Account />
)
}

export default function App() {
return (
<EasybaseProvider ebconfig={ebconfig}>
<Router />
</EasybaseProvider>
)
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center'
},
accountInput: {
height: 40,
borderColor: 'gray',
borderWidth: 1,
width: "75%",
margin: 10,
fontSize: 22,
textAlign: "center"
},
title: {
fontSize: 30,
fontWeight: "500",
fontStyle: "italic",
marginBottom: 30
}
});
55 changes: 55 additions & 0 deletions native-example/android/app/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# To learn about Buck see [Docs](https://buckbuild.com/).
# To run your application with Buck:
# - install Buck
# - `npm start` - to start the packager
# - `cd android`
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
# - `buck install -r android/app` - compile, install and run application
#

load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")

lib_deps = []

create_aar_targets(glob(["libs/*.aar"]))

create_jar_targets(glob(["libs/*.jar"]))

android_library(
name = "all-libs",
exported_deps = lib_deps,
)

android_library(
name = "app-code",
srcs = glob([
"src/main/java/**/*.java",
]),
deps = [
":all-libs",
":build_config",
":res",
],
)

android_build_config(
name = "build_config",
package = "com.nativeexample",
)

android_resource(
name = "res",
package = "com.nativeexample",
res = "src/main/res",
)

android_binary(
name = "app",
keystore = "//android/keystores:debug",
manifest = "src/main/AndroidManifest.xml",
package_type = "debug",
deps = [
":app-code",
],
)
Loading

0 comments on commit 79dc44f

Please sign in to comment.