2023-06-04 23:22:47 -05:00
// Import Stuff
/// React Native
import * as React from 'react'
import { Text } from 'react-native'
import { SafeAreaView } from 'react-native-safe-area-context'
2023-06-04 19:40:57 -05:00
import { WebView } from 'react-native-webview'
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-04 23:22:47 -05:00
// App
export default function App ( ) {
2023-06-04 19:40:57 -05:00
const [ tabs , setTabs ] = React . useState ( [
{
name : "tab-1" ,
component : TabScreen ,
}
] )
const addNewTab = ( ) => {
setTabs ( tabs => [
... tabs ,
{
name : "tab-" + ( parseInt ( tabs . pop ( ) . name . replace ( "tab-" , "" ) ) + 1 ) ,
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
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
onError = { ( ) => Alert . alert ( "Page failed to load" , "The page you're trying to view has failed to load. Either caused by a connection error or the a server-side issue." , [ { text : 'OK' } ] ) }
source = { { uri : 'https://design.penpot.app' } }
javaScriptEnabled = { true }
javaScriptEnabledAndroid = { true }
2023-06-04 23:22:47 -05:00
scalesPageToFit = { false } // Too big if set to true
2023-06-04 19:40:57 -05:00
allowsBackForwardNavigationGestures
/ >
< / 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-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
}