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

139 lines
4 KiB
JavaScript
Raw Normal View History

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</Text>
</View>
)
}
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
/>
</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-07 19:26:41 -05:00
<Text
style={Styles.SettingButton}
onPress={ToggleSettingModal}
>Settings</Text>
<Modal
animationIn={'fadeIn'}
animationOut={'fadeOut'}
isVisible={isModalVisible}
onBackButtonPress={ToggleSettingModal}
onBackdropPress={ToggleSettingModal}
>
<View style={Styles.Settings}>
<Text>Instance</Text>
<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</Text>
<TextInput style={Styles.InstanceSubmit} type="submit" value="Submit"></TextInput>
</View>
</View>
</Modal>
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
}