Skip to content

Commit

Permalink
ensured all tests are present
Browse files Browse the repository at this point in the history
  • Loading branch information
alduzy committed May 20, 2024
1 parent b474821 commit 32f8a55
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import Test1296 from './Test1296';
import Test1299 from './Test1299';
import Test1391 from './Test1391';
import Test1419 from './Test1419';
import Test1463 from './Test1463';
import Test1473 from './Test1473';
import Test1476 from './Test1476';
import Test1509 from './Test1509';
Expand All @@ -96,9 +97,11 @@ import Test1864 from './Test1864';
import Test1970 from './Test1970';
import Test1981 from './Test1981';
import Test2008 from './Test2008';
import Test2028 from './Test2028';
import Test2048 from './Test2048';
import Test2069 from './Test2069';
import Test2118 from './Test2118';
import TestScreenAnimation from './TestScreenAnimation';

enableFreeze(true);

Expand Down
133 changes: 133 additions & 0 deletions tests/src/Test1463.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import React, { useState } from 'react';
import {
Button,
Dimensions,
Image,
StyleSheet,
Text,
View,
} from 'react-native';
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
} from '@react-navigation/native-stack';
import {
GestureHandlerRootView,
ScrollView,
State,
TapGestureHandler,
} from 'react-native-gesture-handler';

const Stack = createNativeStackNavigator();

function First({
navigation,
}: {
navigation: NativeStackNavigationProp<ParamListBase>;
}) {
return (
<View
style={{
flex: 1,
backgroundColor: 'blue',
}}>
<Button
onPress={() => navigation.navigate('Second')}
title="Go to second"
/>
</View>
);
}

function Second() {
return (
<View
style={{
flex: 1,
backgroundColor: 'red',
}}>
<Text style={styles.subTitle}>
Use swipe back gesture to go back (iOS only)
</Text>
</View>
);
}

export default function App() {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
fullScreenGestureEnabled: false,
animation: 'fade',
animationMatchesGesture: true,
}}>
<Stack.Screen name="First" component={First} />
<Stack.Screen name="Second" component={Second} />
</Stack.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
);
}

// components

function Post({ onPress }: { onPress?: () => void }) {
const [width] = useState(Math.round(Dimensions.get('screen').width));

return (
<TapGestureHandler
onHandlerStateChange={e =>
e.nativeEvent.oldState === State.ACTIVE && onPress?.()
}>
<View style={styles.post}>
<Text style={styles.title}>Post</Text>
<ScrollView horizontal>{generatePhotos(4, width, 400)}</ScrollView>
<Text style={styles.caption}>Scroll right for more photos</Text>
</View>
</TapGestureHandler>
);
}

// helpers
function generatePhotos(
amount: number,
width: number,
height: number,
): JSX.Element[] {
const startFrom = Math.floor(Math.random() * 20) + 10;
return Array.from({ length: amount }, (_, index) => {
const uri = `https://picsum.photos/id/${
startFrom + index
}/${width}/${height}`;
return <Image style={{ width, height }} key={uri} source={{ uri }} />;
});
}

const styles = StyleSheet.create({
title: {
fontWeight: 'bold',
fontSize: 32,
marginBottom: 8,
marginLeft: 8,
},
subTitle: {
fontSize: 18,
marginVertical: 16,
textAlign: 'center',
},
caption: {
textAlign: 'center',
marginTop: 4,
},
post: {
borderColor: '#ccc',
borderTopWidth: 1,
borderBottomWidth: 1,
paddingVertical: 10,
marginBottom: 16,
backgroundColor: 'white',
},
});
54 changes: 54 additions & 0 deletions tests/src/Test2028.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

import React from 'react';
import { Button, SafeAreaView, View } from 'react-native';

import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { NavigationContainer } from '@react-navigation/native';

const Stack = createNativeStackNavigator();

const TestScreen = ({ navigation }): React.JSX.Element => {
return (
<SafeAreaView>
<Button
title={
'Click me and drag around a bit and I should log something still'
}
onPress={() => {
console.log(Date.now());
}}
/>
<Button
title={'Navigate to modal'}
onPress={() => {
navigation.navigate('Test2');
}}
/>
</SafeAreaView>
);
};
function App(): React.JSX.Element {
return (
<>
<View style={{ width: 100, height: 200, backgroundColor: 'red' }} />
<NavigationContainer>
<Stack.Navigator
initialRouteName="Test"
screenOptions={{ presentation: 'modal' }}>
<Stack.Screen
name="Test"
component={TestScreen}
options={{ headerShown: true }}
/>
<Stack.Screen
name="Test2"
component={TestScreen}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
</>
);
}

export default App;
84 changes: 84 additions & 0 deletions tests/src/TestScreenAnimation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { View, StyleSheet, Button } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
} from 'react-native-screens/native-stack';
import { GestureDetectorProvider } from 'react-native-screens/gesture-handler';

type StackParamList = {
ScreenA: undefined;
ScreenB: undefined;
ScreenC: undefined;
};

interface MainScreenProps {
navigation: NativeStackNavigationProp<StackParamList, 'ScreenA'>;
}

const MainScreen = ({ navigation }: MainScreenProps): JSX.Element => (
<View style={{ ...styles.container, backgroundColor: 'moccasin' }}>
<Button title="Go ScreenB" onPress={() => {
navigation.navigate('ScreenB')
}} />
<Button onPress={() => navigation.pop()} title="🔙 Back to Examples" />
</View>
);

interface ScreenBProps {
navigation: NativeStackNavigationProp<StackParamList, 'ScreenB'>;
}

const ScreenB = ({ navigation }: ScreenBProps): JSX.Element => (
<View style={{ ...styles.container, backgroundColor: 'thistle' }}>
<Button title="Go ScreenC" onPress={() => navigation.navigate('ScreenC')} />
<Button title="Go back" onPress={() => navigation.goBack()} />
</View>
);

interface ScreenCProps {
navigation: NativeStackNavigationProp<StackParamList, 'ScreenC'>;
}

const ScreenC = ({ navigation }: ScreenCProps): JSX.Element => (
<View style={{ ...styles.container, backgroundColor: 'blue' }}>
<Button title="Go back" onPress={() => navigation.goBack()} />
</View>
);

const Stack = createNativeStackNavigator<StackParamList>();

const App = (): JSX.Element => (
<GestureHandlerRootView style={{ flex: 1 }}>
<NavigationContainer>
<GestureDetectorProvider>
<Stack.Navigator
screenOptions={{
headerHideBackButton: true,
stackAnimation: 'none',
}}>
<Stack.Screen name="ScreenA" component={MainScreen} />
<Stack.Screen
name="ScreenB"
component={ScreenB}
options={{
goBackGesture: 'twoDimensionalSwipe',
}}
/>
<Stack.Screen name="ScreenC" component={ScreenC} />
</Stack.Navigator>
</GestureDetectorProvider>
</NavigationContainer>
</GestureHandlerRootView>
);

const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 10,
},
});

export default App;

0 comments on commit 32f8a55

Please sign in to comment.