Skip to content

Commit

Permalink
chore: updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Jan 6, 2022
1 parent 9b0fffd commit d9c3ea6
Show file tree
Hide file tree
Showing 10 changed files with 2,367 additions and 3,372 deletions.
3 changes: 2 additions & 1 deletion example/app.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@gorhom/portal-example",
"name": "React Native Portal",
"displayName": "React Native Portal Example",
"expo": {
"name": "@gorhom/portal-example",
Expand All @@ -17,6 +17,7 @@
"ios": {
"supportsTablet": true
},
"userInterfaceStyle": "automatic",
"assetBundlePatterns": [
"**/*"
]
Expand Down
45 changes: 24 additions & 21 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,34 @@
"test": "jest"
},
"dependencies": {
"@gorhom/showcase-template": "^2.0.4",
"@gorhom/showcase-template": "^2.1.0",
"@react-native-community/masked-view": "0.1.11",
"@react-navigation/bottom-tabs": "^5.11.11",
"@react-navigation/native": "^5.9.4",
"@react-navigation/stack": "^5.14.5",
"expo": "^41.0.1",
"expo-splash-screen": "~0.10.2",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "0.63.4",
"react-native-gesture-handler": "~1.10.3",
"react-native-reanimated": "~2.2.0",
"react-native-safe-area-context": "3.2.0",
"react-native-screens": "~3.3.0",
"react-native-unimodules": "~0.13.3",
"react-native-web": "~0.16.5"
"@react-native-masked-view/masked-view": "0.2.6",
"@react-navigation/bottom-tabs": "^6.0.9",
"@react-navigation/native": "^6.0.6",
"@react-navigation/native-stack": "^6.2.5",
"@react-navigation/stack": "^6.0.11",
"expo": "^44.0.0",
"expo-splash-screen": "~0.14.1",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-gesture-handler": "~2.1.0",
"react-native-reanimated": "~2.3.1",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.10.1",
"react-native-unimodules": "~0.15.0",
"react-native-web": "0.17.1"
},
"devDependencies": {
"@babel/core": "~7.9.0",
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.18",
"@expo/webpack-config": "^0.12.76",
"@types/react": "~16.9.35",
"@types/react-native": "~0.63.2",
"@expo/webpack-config": "~0.16.2",
"@types/react": "~17.0.21",
"@types/react-native": "~0.64.12",
"babel-loader": "^8.2.3",
"babel-plugin-module-resolver": "^4.1.0",
"babel-preset-expo": "8.3.0",
"typescript": "~4.0.0"
"babel-preset-expo": "9.0.1",
"typescript": "~4.3.5"
}
}
37 changes: 37 additions & 0 deletions example/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { ReactNode } from 'react';
import { ViewStyle, TextStyle, StyleSheet } from 'react-native';
import { ShowcaseButton, ShowcaseLabel } from '@gorhom/showcase-template';

interface ButtonProps {
label: string;
endContent?: string | ReactNode;
style?: ViewStyle;
labelStyle?: TextStyle;
onPress: () => void;
}

export const Button = ({
label,
endContent,
style,
labelStyle,
onPress,
}: ButtonProps) => (
<ShowcaseButton
containerStyle={style}
contentContainerStyle={styles.container}
onPress={onPress}
>
<ShowcaseLabel style={labelStyle}>{label}</ShowcaseLabel>
{endContent && endContent}
</ShowcaseButton>
);

const styles = StyleSheet.create({
container: {
flexDirection: 'row',
justifyContent: 'space-between',
alignContent: 'center',
alignItems: 'center',
},
});
82 changes: 82 additions & 0 deletions example/src/components/CounterModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React from 'react';
import {
GestureResponderEvent,
StyleSheet,
Text,
TouchableOpacity,
TouchableWithoutFeedback,
View,
} from 'react-native';

interface SimpleModalProps {
count: number;
onIncrease: () => void;
onPress: (event: GestureResponderEvent) => void;
}

export const CounterModal = ({
count,
onIncrease,
onPress,
}: SimpleModalProps) => {
return (
<TouchableWithoutFeedback onPress={onPress} style={styles.buttonContainer}>
<View style={styles.backdropContainer}>
<View style={styles.modalContainer}>
<Text>Counter Modal</Text>
<View
style={{
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginTop: 12,
}}
>
<Text>{count}</Text>
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity
style={styles.actionButton}
onPress={onIncrease}
>
<Text>+</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.actionButton}
onPress={onIncrease}
>
<Text>-</Text>
</TouchableOpacity>
</View>
</View>
</View>
</View>
</TouchableWithoutFeedback>
);
};

const styles = StyleSheet.create({
backdropContainer: {
...StyleSheet.absoluteFillObject,
backgroundColor: 'rgba(0, 0, 0, 0.5)',
justifyContent: 'center',
alignItems: 'center',
},
buttonContainer: {
...StyleSheet.absoluteFillObject,
justifyContent: 'center',
alignItems: 'center',
},
modalContainer: {
padding: 24,
backgroundColor: 'white',
},
actionButton: {
width: 25,
height: 25,
borderRadius: 25,
marginHorizontal: 2,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
});
54 changes: 0 additions & 54 deletions example/src/screens/HomeScreen.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion example/src/screens/ModalScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const styles = StyleSheet.create({
});

export default () => (
<Tab.Navigator>
<Tab.Navigator screenOptions={{ headerShown: false }}>
<Tab.Screen name="Home" component={BasicScreen} />
<Tab.Screen name="Settings" component={BasicScreen} />
</Tab.Navigator>
Expand Down
89 changes: 89 additions & 0 deletions example/src/screens/NativeScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { useCallback, useState } from 'react';
import { Platform, StyleSheet, View } from 'react-native';
import { Portal } from '@gorhom/portal';
import { ShowcaseLabel } from '@gorhom/showcase-template';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { useNavigation } from '@react-navigation/native';
import { FullWindowOverlay } from 'react-native-screens';
import { Button } from '../components/Button';
import { CounterModal } from '../components/CounterModal';

const Stack = createNativeStackNavigator();

const DummyScreen = () => {
const [showModal, setShowModal] = useState(false);
const [count, setCount] = useState(0);
const { navigate } = useNavigation();

const handleModalTogglePress = useCallback(() => {
setShowModal(state => !state);
}, []);

const handleNavigatePress = useCallback(() => {
navigate({
// @ts-ignore
name: 'B',
key: `screen-a-${Math.random()}`,
});
}, [navigate]);

return (
<View style={styles.container}>
<ShowcaseLabel children={count} />
<Button
label={`${showModal ? 'Hide' : 'Show'} Modal`}
onPress={handleModalTogglePress}
/>

<Button label="Navigate to Native Modal" onPress={handleNavigatePress} />

{showModal && (
<Portal name="modal">
<FullWindowOverlay style={StyleSheet.absoluteFill}>
<CounterModal
count={count}
onIncrease={() => setCount(count + 1)}
onPress={handleModalTogglePress}
/>
</FullWindowOverlay>
</Portal>
)}
</View>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
alignContent: 'center',
},
button: {
paddingHorizontal: 24,
paddingVertical: 12,
borderRadius: 24,
backgroundColor: '#333',
},
text: {
color: 'white',
},
});

export default () => (
<Stack.Navigator>
<Stack.Screen
name="A"
component={DummyScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="B"
component={DummyScreen}
options={{
presentation: 'formSheet',
headerShown: Platform.OS === 'ios',
}}
/>
</Stack.Navigator>
);
5 changes: 4 additions & 1 deletion example/src/screens/PopoverScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ const styles = StyleSheet.create({
});

export default () => (
<Tab.Navigator sceneContainerStyle={{ height: WINDOW_HEIGHT }}>
<Tab.Navigator
sceneContainerStyle={{ height: WINDOW_HEIGHT }}
screenOptions={{ headerShown: false }}
>
<Tab.Screen name="Home" component={BasicScreen} />
<Tab.Screen name="Settings" component={BasicScreen} />
</Tab.Navigator>
Expand Down
23 changes: 20 additions & 3 deletions example/src/screens/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const screens = [
import { Platform } from 'react-native';

let screens = [
{
title: '',
title: 'Basic',
data: [
{
name: 'Basic',
name: 'Default',
slug: 'basic',
getScreen: () => require('./BasicScreen').default,
},
Expand All @@ -20,3 +22,18 @@ export const screens = [
],
},
];

if (Platform.OS !== 'web') {
screens.push({
title: 'Advance',
data: [
{
name: 'Native Screens',
slug: 'native',
getScreen: () => require('./NativeScreen').default,
},
],
});
}

export { screens };
Loading

0 comments on commit d9c3ea6

Please sign in to comment.