Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact(TVOS): using common example src #2173

Merged
merged 25 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f436436
chore: bump rn
alduzy May 20, 2024
4babc4d
Merge remote-tracking branch 'origin/main' into @alduzy/bump-tvosexam…
alduzy May 22, 2024
9c62a03
chore: rebuild TVOSExample
alduzy May 22, 2024
acd49b5
moved expo files to gitignore
alduzy May 22, 2024
26b073e
tv os worklfow mac os v bump
alduzy May 28, 2024
1c80e85
tv os worklfow script fix
alduzy May 28, 2024
c9e83b7
went back to using tvos own src dir
alduzy May 28, 2024
5ac1bce
using latest xcode
alduzy May 28, 2024
ab60d31
updated script
alduzy May 28, 2024
4b1ea61
try simplified script
alduzy May 28, 2024
4a4d8ca
revert try simplified script
alduzy May 28, 2024
4ef5ecc
Merge remote-tracking branch 'origin/main' into @alduzy/rebuild-tvose…
alduzy Jun 6, 2024
94ba59f
chore: podfile lock update
alduzy Jun 6, 2024
ce2a78c
refact(TVOS): using common example src
alduzy Jun 6, 2024
a3c8f3f
Merge branch 'main' into @alduzy/unify-tvosexample
alduzy Jun 10, 2024
2fc209f
fix: removed unnecessary workflow step
alduzy Jun 10, 2024
411907d
refact: newline
alduzy Jun 10, 2024
c7d389a
added Platform ternary for TVOS example
alduzy Jun 10, 2024
4d12007
refact: simplified examples and playgrounds
alduzy Jun 11, 2024
1e5856e
refact: platform check adjusted
alduzy Jun 11, 2024
5654ac0
refact: less nesting
alduzy Jun 11, 2024
dfd02db
Merge remote-tracking branch 'origin/main' into @alduzy/unify-tvosexa…
alduzy Jun 11, 2024
3ada82c
refact: extending root tsconfig
alduzy Jun 11, 2024
fabecad
feat: changing title icon based on platform
alduzy Jun 11, 2024
aada1aa
feat: disabling instead of hiding N/A screens
alduzy Jun 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions TVOSExample/App.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import HomeScreen from './src/HomeScreen';
import BottomTabsExample from './src/BottomTabsExample';
import ModalsExample from './src/ModalsExample';
import NativeStackExample from './src/NativeStackExample';
import App from '../apps/examples';

const Stack = createNativeStackNavigator();

export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ title: '📺 React Native Screens' }}
/>
<Stack.Screen name="Bottom Tabs" component={BottomTabsExample} />
<Stack.Screen name="Modals" component={ModalsExample} />
<Stack.Screen name="Native Stack" component={NativeStackExample} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;
40 changes: 0 additions & 40 deletions TVOSExample/src/BottomTabsExample.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions TVOSExample/src/HomeScreen.tsx

This file was deleted.

72 changes: 0 additions & 72 deletions TVOSExample/src/ModalsExample.tsx

This file was deleted.

54 changes: 0 additions & 54 deletions TVOSExample/src/NativeStackExample.tsx

This file was deleted.

1 change: 0 additions & 1 deletion TVOSExample/src/examples.ts

This file was deleted.

9 changes: 0 additions & 9 deletions TVOSExample/src/styles.ts

This file was deleted.

2 changes: 1 addition & 1 deletion TVOSExample/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "@react-native/typescript-config/tsconfig.json"
"extends": "../tsconfig.json"
}
61 changes: 40 additions & 21 deletions apps/examples/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ const SCREENS: Record<
title: string;
component: () => React.JSX.Element;
type: 'example' | 'playground';
isTVOSReady?: boolean;
}
> = {
SimpleNativeStack: {
title: 'Simple Native Stack',
component: SimpleNativeStack,
type: 'example',
isTVOSReady: true,
},
SwipeBackAnimation: {
title: 'Swipe Back Animation',
Expand All @@ -59,16 +61,19 @@ const SCREENS: Record<
title: 'Stack Presentation',
component: StackPresentation,
type: 'example',
isTVOSReady: true,
},
BottomTabsAndStack: {
title: 'Bottom tabs and native stack',
component: BottomTabsAndStack,
type: 'example',
isTVOSReady: true,
},
Modals: {
title: 'Modals',
component: Modals,
type: 'example',
isTVOSReady: true,
},
HeaderOptions: {
title: 'Header Options',
Expand Down Expand Up @@ -107,6 +112,18 @@ const SCREENS: Record<
},
};

const isPlatformReady = (name: keyof typeof SCREENS) => {
if (Platform.isTV) {
return !!SCREENS[name].isTVOSReady;
}

return true;
};

const screens = Object.keys(SCREENS);
const examples = screens.filter(name => SCREENS[name].type === 'example');
const playgrounds = screens.filter(name => SCREENS[name].type === 'playground');

type RootStackParamList = {
Main: undefined;
} & {
Expand All @@ -133,27 +150,25 @@ const MainScreen = ({ navigation }: MainScreenProps): React.JSX.Element => (
<Text style={styles.label} testID="root-screen-examples-header">
alduzy marked this conversation as resolved.
Show resolved Hide resolved
Examples
</Text>
{Object.keys(SCREENS)
.filter(name => SCREENS[name].type === 'example')
.map(name => (
<ListItem
key={name}
testID={`root-screen-example-${name}`}
title={SCREENS[name].title}
onPress={() => navigation.navigate(name)}
/>
))}
{examples.map(name => (
<ListItem
key={name}
testID={`root-screen-example-${name}`}
title={SCREENS[name].title}
onPress={() => navigation.navigate(name)}
disabled={!isPlatformReady(name)}
/>
))}
<Text style={styles.label}>Playgrounds</Text>
{Object.keys(SCREENS)
.filter(name => SCREENS[name].type === 'playground')
.map(name => (
<ListItem
key={name}
testID={`root-screen-playground-${name}`}
title={SCREENS[name].title}
onPress={() => navigation.navigate(name)}
/>
))}
{playgrounds.map(name => (
<ListItem
key={name}
testID={`root-screen-playground-${name}`}
title={SCREENS[name].title}
onPress={() => navigation.navigate(name)}
disabled={!isPlatformReady(name)}
/>
))}
</ScrollView>
);

Expand All @@ -164,7 +179,11 @@ const ExampleApp = (): React.JSX.Element => (
<Stack.Navigator>
<Stack.Screen
name="Main"
options={{ title: '📱 React Native Screens Examples' }}
options={{
title: `${
Platform.isTV ? '📺' : '📱'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice touch 😄

} React Native Screens Examples`,
}}
component={MainScreen}
/>
{Object.keys(SCREENS).map(name => (
Expand Down
15 changes: 12 additions & 3 deletions apps/examples/src/shared/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ interface Props {
title: string;
onPress: () => void;
testID?: string;
disabled?: boolean;
}

export const ListItem = ({ title, onPress, testID }: Props): React.JSX.Element => {
export const ListItem = ({
title,
onPress,
testID,
disabled,
}: Props): React.JSX.Element => {
return (
<TouchableOpacity onPress={onPress} testID={testID}>
<TouchableOpacity onPress={onPress} testID={testID} disabled={disabled}>
<View style={styles.container}>
<Text style={styles.title}>{title}</Text>
<Text style={[styles.title, disabled && styles.disabled]}>{disabled && '(N/A) '}{title}</Text>
</View>
</TouchableOpacity>
);
Expand All @@ -27,6 +33,9 @@ const styles = StyleSheet.create({
borderColor: '#ccc',
borderWidth: 1,
},
disabled: {
color: 'gray',
},
title: {
color: 'black',
},
Expand Down
Loading