This repository has been archived on 2024-07-03. You can view files and clone it, but cannot push or open issues or pull requests.
Penpot-App/App.js

86 lines
2.4 KiB
JavaScript
Raw Normal View History

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
/>
</SafeAreaView>
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}
/>)
}
</Tab.Navigator>
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}
>+</Text>
2023-06-04 19:40:57 -05:00
</NavigationContainer>
2023-06-04 23:22:47 -05:00
)
2023-06-04 19:40:57 -05:00
}