2023-06-04 23:22:47 -05:00
// Import Stuff
/// React Native
import * as React from 'react'
2023-06-09 02:00:28 -05:00
import { useState } from "react"
2023-06-07 19:26:41 -05:00
import { Alert , AsyncStorage , Text , TextInput , UseState , View } from 'react-native'
2023-06-04 23:22:47 -05:00
import { SafeAreaView } from 'react-native-safe-area-context'
2023-06-04 19:40:57 -05:00
import { WebView } from 'react-native-webview'
2023-06-09 02:00:28 -05:00
import Modal from "react-native-modal"
2023-06-04 19:40:57 -05:00
2023-06-04 23:22:47 -05:00
/// React Native Navigation
import { NavigationContainer } from '@react-navigation/native'
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs'
2023-06-04 19:40:57 -05:00
2023-06-04 23:22:47 -05:00
/// Expo Modules
import * as SystemUI from 'expo-system-ui'
2023-06-04 19:40:57 -05:00
2023-06-04 23:22:47 -05:00
/// Options
import ScreenOptions from './options/TabOptions'
/// Stylesheets
import Styles from './stylesheets/style'
2023-06-04 19:40:57 -05:00
2023-06-04 23:22:47 -05:00
// Others
SystemUI . setBackgroundColorAsync ( "black" )
const Tab = createMaterialTopTabNavigator ( )
2023-06-04 19:40:57 -05:00
2023-06-07 19:26:41 -05:00
let InstanceURL = 'https://design.penpot.app/'
2023-06-04 23:22:47 -05:00
// App
export default function App ( ) {
2023-06-09 02:10:31 -05:00
const [ isModalVisible , setModalVisible ] = useState ( false ) ;
const ToggleSettingModal = ( ) => {
setModalVisible ( ! isModalVisible ) ;
} ;
2023-06-07 19:26:41 -05:00
2023-06-04 19:40:57 -05:00
const [ tabs , setTabs ] = React . useState ( [
{
2023-06-07 19:26:41 -05:00
name : "1" ,
2023-06-04 19:40:57 -05:00
component : TabScreen ,
}
] )
const addNewTab = ( ) => {
setTabs ( tabs => [
2023-06-09 02:10:31 -05:00
... tabs ,
2023-06-04 19:40:57 -05:00
{
2023-06-07 19:26:41 -05:00
name : "" + ( parseInt ( tabs . pop ( ) . name . replace ( "" , "" ) ) + 1 ) ,
2023-06-04 19:40:57 -05:00
component : TabScreen ,
}
] )
}
2023-06-04 23:22:47 -05:00
const remove = ( route ) => { setTabs ( tabs => tabs . filter ( tab => tab . name !== route . name ) ) }
2023-06-04 19:40:57 -05:00
2023-06-09 02:00:28 -05:00
function Loading ( ) {
return (
< View >
< Text > Loading < / T e x t >
< / V i e w >
)
}
2023-06-04 19:40:57 -05:00
function TabScreen ( { route } ) {
return (
2023-06-04 23:22:47 -05:00
< SafeAreaView style = { Styles . Container } >
2023-06-04 19:40:57 -05:00
< WebView
2023-06-09 02:00:28 -05:00
onError = { ( syntheticEvent ) => { const { nativeEvent } = syntheticEvent } }
renderError = { ( ) => Alert . alert ( "Something went wrong" , "The page you are trying to load has either crashed or there is no connection. Please check your Instance setting to make sure the URL is correct." , [ { text : 'OK' } ] ) }
renderLoading = { ( ) => < Loading / > }
startInLoadingState = { true }
2023-06-07 19:26:41 -05:00
source = { { uri : InstanceURL } }
2023-06-04 19:40:57 -05:00
javaScriptEnabled = { true }
javaScriptEnabledAndroid = { true }
2023-06-07 19:26:41 -05:00
scalesPageToFit = { false }
2023-06-09 02:00:28 -05:00
bounces = { false }
pullToRefreshEnabled = { false }
contentMode = { 'desktop' }
androidLayerType = { 'software' }
2023-06-04 19:40:57 -05:00
allowsBackForwardNavigationGestures
2023-06-07 19:26:41 -05:00
style = { { backgroundColor : '#202020' } }
2023-06-04 19:40:57 -05:00
/ >
< / S a f e A r e a V i e w >
2023-06-04 23:22:47 -05:00
)
2023-06-04 19:40:57 -05:00
}
return (
< NavigationContainer >
2023-06-04 23:22:47 -05:00
< Tab . Navigator
optimizationsEnabled = { true }
backBehavior = 'none'
keyboardDismissMode = 'none'
screenOptions = { {
tabBarGap : 10 ,
tabBarAndroidRipple : { borderless : false } ,
} }
{ ... { screenOptions } } >
2023-06-04 19:40:57 -05:00
{
tabs . map ( tab => < Tab . Screen
key = { tab . name }
name = { tab . name }
component = { tab . component }
/ > )
}
< / T a b . N a v i g a t o r >
2023-06-04 23:22:47 -05:00
{ /* {route.name !== "tab-1" && <Text onPress={() => remove(route)}>close me</Text>} */ }
< Text
style = { Styles . AddButton }
onPress = { addNewTab }
> + < / T e x t >
2023-06-07 19:26:41 -05:00
< Text
style = { Styles . SettingButton }
onPress = { ToggleSettingModal }
> Settings < / T e x t >
< Modal
animationIn = { 'fadeIn' }
animationOut = { 'fadeOut' }
isVisible = { isModalVisible }
onBackButtonPress = { ToggleSettingModal }
onBackdropPress = { ToggleSettingModal }
>
< View style = { Styles . Settings } >
< Text > Instance < / T e x t >
< TextInput
style = { Styles . InstanceForm }
type = "text"
2023-06-09 02:00:28 -05:00
onChange = { ( e ) => SetInstance ( e . target . value ) }
2023-06-07 19:26:41 -05:00
placeholder = "https://design.penpot.app/"
aria - label = "InstanceURL"
/ >
< View style = { { flexDirection : "row" , alignSelf : 'flex-end' } } >
< Text style = { Styles . InstanceCancel } onPress = { ToggleSettingModal } > Cancel < / T e x t >
< TextInput style = { Styles . InstanceSubmit } type = "submit" value = "Submit" > < / T e x t I n p u t >
< / V i e w >
< / V i e w >
< / M o d a l >
2023-06-04 19:40:57 -05:00
< / N a v i g a t i o n C o n t a i n e r >
2023-06-04 23:22:47 -05:00
)
2023-06-04 19:40:57 -05:00
}