-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base on the work, you can download the apk to use the app on Android
- Loading branch information
1 parent
493a386
commit 9ffb5f5
Showing
15 changed files
with
11,754 additions
and
3,898 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
import { StatusBar } from 'expo-status-bar'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
import React from "react"; | ||
import Login from "./Login"; | ||
import OpenLink from "./OpenLink"; | ||
import { Alert } from "react-native"; | ||
|
||
export default function App() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text>Open up App.js to start working on your app!</Text> | ||
<StatusBar style="auto" /> | ||
</View> | ||
); | ||
} | ||
export default function Chocolate() { | ||
const [url, setURL] = React.useState() | ||
const [work, setWork] = React.useState(false) | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: '#fff', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
}); | ||
console.log(url) | ||
|
||
function loadChocolate() { | ||
|
||
const regexExpurl = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/; | ||
const regexExpIP = /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\:?([0-9]{1,5})?/ | ||
|
||
let regexWork = false; | ||
let isChocolate = false; | ||
let tempURL = url | ||
if (tempURL.startsWith("http://") || tempURL.startsWith("https://")) { | ||
tempURL = tempURL.replace("https://", "").replace("http://", "") | ||
} | ||
checkURL = `http://${tempURL}/isChocolate` | ||
if (regexExpurl.test(tempURL) || regexExpIP.test(tempURL)) { | ||
regexWork = true; | ||
console.log("fetch -1") | ||
fetch(checkURL).then(response => { console.log("response"+response); return response.json(); }).then(data => { | ||
if (data.isChocolate) { | ||
isChocolate = true; | ||
} else { | ||
Alert.alert("Chocolate", "This is not a Chocolate Server") | ||
isChocolate = false; | ||
}}).then(() => { | ||
if (regexWork && isChocolate) { | ||
setWork(true) | ||
}}).catch((error) => { | ||
Alert.alert("Chocolate Server Error", "This is not a Chocolate Server") | ||
}) | ||
} else { | ||
Alert.alert("Chocolate URL Error", "This is not a valid URL") | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
{!work ? <Login setURL={setURL} loadChocolate={loadChocolate} /> : <OpenLink url={url} />} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { View, TextInput, TouchableOpacity, StatusBar, Text, StyleSheet } from "react-native" | ||
|
||
export default function Login({ setURL, loadChocolate }) { | ||
return ( | ||
<View style={styles.container}> | ||
<TextInput placeholder="The Chocolate Server url" | ||
style={styles.inputText} | ||
onChangeText={(text) => setURL(text)} /> | ||
<TouchableOpacity style={styles.button} title="Connect" onPress={() => loadChocolate()}><Text style={styles.text}>TEST</Text></TouchableOpacity> | ||
<StatusBar style="auto" /> | ||
</View> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: '#1d1d1d', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
inputText: { | ||
backgroundColor: '#9d9d9d40', | ||
width: 250, | ||
height: 42, | ||
borderRadius: 10, | ||
paddingLeft: 10, | ||
outlineStyle: "none", | ||
color: "white", | ||
elevation: 5, | ||
}, | ||
text: { | ||
color: "white", | ||
fontSize: 13, | ||
}, | ||
button: { | ||
marginTop: 44, | ||
paddingTop: 30, | ||
paddingBottom: 30, | ||
paddingLeft: 40, | ||
paddingRight: 40, | ||
color: "white", | ||
borderRadius: 22, | ||
borderWidth: 1, | ||
borderColor: '#fff', | ||
elevation: 5, | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { WebView } from 'react-native-webview'; | ||
import { Platform, View } from 'react-native'; | ||
|
||
export default function OpenLink({url}) { | ||
return ( | ||
<View style={{flex: 1}}> | ||
{ Platform.OS === 'web' ? ( | ||
<iframe width="100%" height="100%" src={url} frameborder="0"></iframe>) | ||
: | ||
( | ||
<WebView | ||
style={{flex: 1}} | ||
originWhitelist={['*']} | ||
javaScriptEnabled={true} | ||
source={{ uri: url }} /> | ||
)} | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
{ | ||
"expo": { | ||
"name": "chocolatemobileclient", | ||
"slug": "chocolatemobileclient", | ||
"version": "1.0.0", | ||
"orientation": "portrait", | ||
"icon": "./assets/icon.png", | ||
"userInterfaceStyle": "light", | ||
"splash": { | ||
"image": "./assets/splash.png", | ||
"resizeMode": "contain", | ||
"backgroundColor": "#ffffff" | ||
}, | ||
"updates": { | ||
"fallbackToCacheTimeout": 0 | ||
}, | ||
"assetBundlePatterns": [ | ||
"**/*" | ||
], | ||
"ios": { | ||
"supportsTablet": true | ||
}, | ||
"android": { | ||
"adaptiveIcon": { | ||
"foregroundImage": "./assets/adaptive-icon.png", | ||
"backgroundColor": "#FFFFFF" | ||
} | ||
}, | ||
"web": { | ||
"favicon": "./assets/favicon.png" | ||
"expo": { | ||
"name": "Chocolate", | ||
"slug": "chocolatemobileclient", | ||
"version": "1.0.0", | ||
"orientation": "portrait", | ||
"icon": "./assets/logo.png", | ||
"userInterfaceStyle": "dark", | ||
"splash": { | ||
"image": "./assets/splash.png", | ||
"resizeMode": "contain", | ||
"backgroundColor": "#ffffff" | ||
}, | ||
"updates": { | ||
"fallbackToCacheTimeout": 0 | ||
}, | ||
"assetBundlePatterns": [ | ||
"**/*" | ||
], | ||
"ios": { | ||
"supportsTablet": true | ||
}, | ||
"android": { | ||
"adaptiveIcon": { | ||
"foregroundImage": "./assets/logo.png", | ||
"backgroundColor": "#FFFFFF" | ||
}, | ||
"package": "com.imprevisible.chocolatemobileclient" | ||
}, | ||
"web": { | ||
"favicon": "./assets/logo.png" | ||
}, | ||
"extra": { | ||
"eas": { | ||
"projectId": "1ec079ec-54ad-4921-934d-ffb0bcf2bea2" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"build": { | ||
"preview": { | ||
"android": { | ||
"buildType": "apk" | ||
} | ||
}, | ||
"preview2": { | ||
"android": { | ||
"gradleCommand": ":app:assembleRelease" | ||
} | ||
}, | ||
"preview3": { | ||
"developmentClient": true | ||
}, | ||
"production": { | ||
"android": { | ||
"buildType": "apk", | ||
"gradleCommand": ":app:assembleRelease" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { registerRootComponent } from 'expo'; | ||
|
||
import App from './App'; | ||
|
||
// registerRootComponent calls AppRegistry.registerComponent('main', () => App); | ||
// It also ensures that whether you load the app in Expo Go or in a native build, | ||
// the environment is set up appropriately | ||
registerRootComponent(App); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Learn more https://docs.expo.io/guides/customizing-metro | ||
const { getDefaultConfig } = require('expo/metro-config'); | ||
|
||
module.exports = getDefaultConfig(__dirname); |
Oops, something went wrong.