Skip to content

Commit

Permalink
Reformat part of test examples in TestsExample app
Browse files Browse the repository at this point in the history
  • Loading branch information
kkafar committed Jul 19, 2023
1 parent d40dc02 commit b643c2f
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 221 deletions.
38 changes: 26 additions & 12 deletions TestsExample/src/Test1031.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
import * as React from 'react';
import {Button} from 'react-native';
import {NavigationContainer, ParamListBase} from '@react-navigation/native';
import {createNativeStackNavigator, NativeStackNavigationProp, useHeaderHeight} from 'react-native-screens/native-stack';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
useHeaderHeight,
} from 'react-native-screens/native-stack';

const Stack = createNativeStackNavigator();

export default function App() {
return (
<NavigationContainer>
<Stack.Navigator screenOptions={{stackPresentation: 'formSheet', headerShown: false}}>
<Stack.Navigator
screenOptions={{stackPresentation: 'formSheet', headerShown: false}}>
<Stack.Screen name="First" component={First} />
<Stack.Screen
name="Second"
component={Second}
/>
<Stack.Screen name="Second" component={Second} />
</Stack.Navigator>
</NavigationContainer>
);
}

function First({navigation}: {navigation: NativeStackNavigationProp<ParamListBase>}) {
function First({
navigation,
}: {
navigation: NativeStackNavigationProp<ParamListBase>;
}) {
console.log(useHeaderHeight());
return (
<Button title="Tap me for second screen" onPress={() => navigation.navigate('Second')} />

<Button
title="Tap me for second screen"
onPress={() => navigation.navigate('Second')}
/>
);
}

function Second({navigation}: {navigation: NativeStackNavigationProp<ParamListBase>}) {
function Second({
navigation,
}: {
navigation: NativeStackNavigationProp<ParamListBase>;
}) {
console.log(useHeaderHeight());
return (
<Button title="Tap me for first screen" onPress={() => navigation.navigate('First')} />
<Button
title="Tap me for first screen"
onPress={() => navigation.navigate('First')}
/>
);
}

5 changes: 4 additions & 1 deletion TestsExample/src/Test1032.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ function First({
function Second() {
return (
<View style={{backgroundColor: '#FFF'}}>
<Button title="Swipe back to see if button click triggers" onPress={() => Alert.alert('Click detected')} />
<Button
title="Swipe back to see if button click triggers"
onPress={() => Alert.alert('Click detected')}
/>
</View>
);
}
6 changes: 3 additions & 3 deletions TestsExample/src/Test1036.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const App = () => {
screenOptions={{
headerTitle: 'Title',
searchBar: {
onCancelButtonPress: ()=>{
console.log('cancel button press')
}
onCancelButtonPress: () => {
console.log('cancel button press');
},
},
}}>
<Stack.Screen name="Screen" component={Screen} />
Expand Down
18 changes: 9 additions & 9 deletions TestsExample/src/Test1072.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { Dimensions, Image, StyleSheet, Text, View } from 'react-native';
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
import React, {useState} from 'react';
import {Dimensions, Image, StyleSheet, Text, View} from 'react-native';
import {NavigationContainer, ParamListBase} from '@react-navigation/native';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
Expand Down Expand Up @@ -41,7 +41,7 @@ function Second() {

export default function App() {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<GestureHandlerRootView style={{flex: 1}}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
Expand All @@ -59,12 +59,12 @@ export default function App() {

// components

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

return (
<TapGestureHandler
onHandlerStateChange={(e) =>
onHandlerStateChange={e =>
e.nativeEvent.oldState === State.ACTIVE && onPress?.()
}>
<View style={styles.post}>
Expand All @@ -80,14 +80,14 @@ function Post({ onPress }: { onPress?: () => void }) {
function generatePhotos(
amount: number,
width: number,
height: number
height: number,
): JSX.Element[] {
const startFrom = Math.floor(Math.random() * 20) + 10;
return Array.from({ length: amount }, (_, index) => {
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 }} />;
return <Image style={{width, height}} key={uri} source={{uri}} />;
});
}

Expand Down
10 changes: 8 additions & 2 deletions TestsExample/src/Test1084.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as React from 'react';
import {Button, View} from 'react-native';
import {NavigationContainer, ParamListBase} from '@react-navigation/native';
import {createNativeStackNavigator, NativeStackNavigationProp} from 'react-native-screens/native-stack';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
} from 'react-native-screens/native-stack';

const Stack = createNativeStackNavigator();

Expand Down Expand Up @@ -42,7 +45,10 @@ function Second({
}) {
return (
<View style={{flex: 1, backgroundColor: 'yellow'}}>
<Button title="Tap me for first screen" onPress={() => navigation.goBack()} />
<Button
title="Tap me for first screen"
onPress={() => navigation.goBack()}
/>
</View>
);
}
15 changes: 8 additions & 7 deletions TestsExample/src/Test1096.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react';

import { Button, StyleSheet, View, Modal } from 'react-native';
import {Button, StyleSheet, View, Modal} from 'react-native';
import {FullWindowOverlay} from 'react-native-screens';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
} from 'react-native-screens/native-stack';
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
import {NavigationContainer, ParamListBase} from '@react-navigation/native';

function Home({
navigation,
Expand All @@ -25,8 +25,7 @@ function Home({
<Modal
animationType="slide"
visible={isShowModal}
presentationStyle="pageSheet"
>
presentationStyle="pageSheet">
<View style={styles.container}>
<Button
title="dismiss rn modal"
Expand All @@ -35,10 +34,12 @@ function Home({
</View>
</Modal>
<FullWindowOverlay>
<View style={{flex: 1, justifyContent: 'center'}} pointerEvents="box-none">
<View
style={{flex: 1, justifyContent: 'center'}}
pointerEvents="box-none">
<View style={styles.box} />
<Button title="click me" onPress={() => console.warn('clicked')} />
</View >
</View>
</FullWindowOverlay>
</View>
);
Expand Down Expand Up @@ -66,7 +67,7 @@ export default function App() {
<NativeStack.Screen
name="Modal"
component={ModalScreen}
options={{ stackPresentation: 'modal' }}
options={{stackPresentation: 'modal'}}
/>
</NativeStack.Navigator>
</NavigationContainer>
Expand Down
22 changes: 10 additions & 12 deletions TestsExample/src/Test1097.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable react-hooks/exhaustive-deps */
import * as React from 'react';
import {Button, NativeSyntheticEvent, ScrollView} from 'react-native';
import {
Expand Down Expand Up @@ -91,10 +91,8 @@ function First({navigation}: NativeStackScreenProps<ParamListBase>) {
onPress={() => searchBarRef.current?.focus()}
/>
{items
.filter(
(item) => item.toLowerCase().indexOf(search.toLowerCase()) !== -1,
)
.map((item) => (
.filter(item => item.toLowerCase().indexOf(search.toLowerCase()) !== -1)
.map(item => (
<Button
title={item}
key={item}
Expand Down Expand Up @@ -146,20 +144,20 @@ function Third({navigation}: {navigation: NavigationProp<ParamListBase>}) {
hideNavigationBar: false,
autoCapitalize: 'sentences',
placeholder: 'Some text',
onChangeText: (e: NativeSyntheticEvent<{text: string}>) => console.warn(`Text changed to ${e.nativeEvent.text}`),
onChangeText: (e: NativeSyntheticEvent<{text: string}>) =>
console.warn(`Text changed to ${e.nativeEvent.text}`),
onCancelButtonPress: () => console.warn('Cancel button pressed'),
onSearchButtonPress: () => console.warn('Search button pressed'),
onFocus: () => console.warn('onFocus event'),
onBlur: () => console.warn('onBlur event'),
}
};

React.useEffect(() => {
navigation.setOptions({
searchBar: searchBarProps
})
searchBar: searchBarProps,
});
}, [navigation]);


return (
<ScrollView
contentInsetAdjustmentBehavior="automatic"
Expand All @@ -172,7 +170,7 @@ function Third({navigation}: {navigation: NavigationProp<ParamListBase>}) {
title="Focus search bar"
onPress={() => searchBarRef.current?.focus()}
/>
<Button
<Button
title="Remove focus from search bar"
onPress={() => searchBarRef.current?.blur()}
/>
Expand Down Expand Up @@ -201,5 +199,5 @@ function Third({navigation}: {navigation: NavigationProp<ParamListBase>}) {
onPress={() => searchBarRef.current?.focus()}
/>
</ScrollView>
)
);
}
3 changes: 2 additions & 1 deletion TestsExample/src/Test111.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const Screen1 = () => {
}}>
<Button
title="Go to Screen 2"
onPress={() => navigation.navigate('Screen2')} />
onPress={() => navigation.navigate('Screen2')}
/>
</View>
);
};
Expand Down
2 changes: 1 addition & 1 deletion TestsExample/src/Test1153.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
NativeStackNavigationProp,
} from 'react-native-screens/native-stack';
import {SafeAreaView} from 'react-native-safe-area-context';
import { ScrollView } from 'react-native-gesture-handler';
import {ScrollView} from 'react-native-gesture-handler';

const Stack = createNativeStackNavigator();

Expand Down
5 changes: 3 additions & 2 deletions TestsExample/src/Test1162.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react-hooks/exhaustive-deps */
import * as React from 'react';
import {Button, View} from 'react-native';
import {
Expand Down Expand Up @@ -80,7 +81,7 @@ function First({
function TabScreen() {
return (
<View style={{backgroundColor: '#CCC', flex: 1, paddingTop: 200}}>
<View style={{backgroundColor: '#EEE', flex: 1}}></View>
<View style={{backgroundColor: '#EEE', flex: 1}} />
</View>
);
}
Expand All @@ -101,7 +102,7 @@ function Second({
<View style={{backgroundColor: '#333', flex: 1}}>
<Button
title="Change translucent"
onPress={() => setIsTranslucent((prev) => !prev)}
onPress={() => setIsTranslucent(prev => !prev)}
/>
</View>
</View>
Expand Down
42 changes: 32 additions & 10 deletions TestsExample/src/Test1190.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,66 @@
import * as React from 'react';
import {Button} from 'react-native';
import {NavigationContainer, ParamListBase} from '@react-navigation/native';
import {createNativeStackNavigator, NativeStackNavigationProp} from 'react-native-screens/native-stack';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
} from 'react-native-screens/native-stack';

type Props = {
navigation: NativeStackNavigationProp<ParamListBase>;
}
};

const Stack = createNativeStackNavigator();

export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="First" component={First} options={{stackAnimation: 'none'}}/>
<Stack.Screen
name="First"
component={First}
options={{stackAnimation: 'none'}}
/>
<Stack.Screen
name="Second"
component={Second}
options={{stackAnimation: 'slide_from_bottom', replaceAnimation: 'push'}}
options={{
stackAnimation: 'slide_from_bottom',
replaceAnimation: 'push',
}}
/>
</Stack.Navigator>
</NavigationContainer>
);
}

function First({navigation} : Props) {
function First({navigation}: Props) {
return (
<>
<Button title="Tap me for push second screen" onPress={() => navigation.push('Second')} />
<Button title="Tap me for replace with second screen" onPress={() => navigation.replace('Second')} />
<Button
title="Tap me for push second screen"
onPress={() => navigation.push('Second')}
/>
<Button
title="Tap me for replace with second screen"
onPress={() => navigation.replace('Second')}
/>
<Button title="Tap me for go back" onPress={() => navigation.goBack()} />
</>
);
}

function Second({navigation} : Props) {
function Second({navigation}: Props) {
return (
<>
<Button title="Tap me for push first screen" onPress={() => navigation.push('First')} />
<Button title="Tap me for replace with first screen" onPress={() => navigation.replace('First')} />
<Button
title="Tap me for push first screen"
onPress={() => navigation.push('First')}
/>
<Button
title="Tap me for replace with first screen"
onPress={() => navigation.replace('First')}
/>
<Button title="Tap me for go back" onPress={() => navigation.goBack()} />
</>
);
Expand Down
Loading

0 comments on commit b643c2f

Please sign in to comment.