Skip to content

Commit 98cb1e7

Browse files
j-piaseckim-bert
andauthored
[Example] Add an in-app console viewer (#4313)
## Description Adds a console write interceptor and an in-app console viewer using it. The logs are still appearing in the actual console. ## Test plan Example app https://github.com/user-attachments/assets/66c205fe-3ac3-4123-8b8f-b3d427af3eda --------- Co-authored-by: Michał Bert <63123542+m-bert@users.noreply.github.com>
1 parent af04cd4 commit 98cb1e7

11 files changed

Lines changed: 797 additions & 64 deletions

File tree

apps/common-app/App.tsx

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ import {
2424
Switch,
2525
Touchable,
2626
} from 'react-native-gesture-handler';
27-
import { useSafeAreaInsets } from 'react-native-safe-area-context';
27+
import {
28+
initialWindowMetrics,
29+
SafeAreaProvider,
30+
useSafeAreaInsets,
31+
} from 'react-native-safe-area-context';
2832

2933
import { COLORS } from './src/common';
34+
import { ConsoleHeaderButton, ConsoleModalProvider } from './src/console';
3035
import { OLD_EXAMPLES } from './src/legacy';
3136
import { TouchableExample } from './src/legacy/release_tests/touchables';
3237
import { ListWithHeader } from './src/ListWithHeader';
@@ -45,41 +50,57 @@ type RootStackParamList = {
4550

4651
const Stack = createStackNavigator<RootStackParamList>();
4752
export default function App() {
53+
return (
54+
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
55+
<AppContent />
56+
</SafeAreaProvider>
57+
);
58+
}
59+
60+
function AppContent() {
4861
const [showLegacyVersion, setShowLegacyVersion] = useState(false);
4962
return (
50-
<GestureHandlerRootView>
51-
<NavigationContainer>
52-
<Stack.Navigator
53-
screenOptions={{
54-
cardStyle: {
55-
// It's important to set height for the screen, without it scroll doesn't work on web platform.
56-
height: Dimensions.get('window').height,
57-
backgroundColor: COLORS.offWhite,
58-
},
59-
headerStyle: {
60-
backgroundColor: COLORS.offWhite,
61-
borderBottomColor: COLORS.headerSeparator,
62-
borderBottomWidth: 1,
63-
},
64-
}}>
65-
<Stack.Screen
66-
name="Home"
67-
options={{ headerShown: false }}
68-
component={MainScreen}
69-
/>
70-
{(showLegacyVersion ? OLD_EXAMPLES : NEW_EXAMPLES)
71-
.flatMap(({ data }) => data)
72-
.flatMap(({ name, component }) => (
63+
<GestureHandlerRootView style={styles.root}>
64+
<ConsoleModalProvider>
65+
<View style={styles.root}>
66+
<NavigationContainer>
67+
<Stack.Navigator
68+
screenOptions={{
69+
cardStyle: {
70+
// It's important to set height for the screen, without it scroll doesn't work on web platform.
71+
height: Dimensions.get('window').height,
72+
backgroundColor: COLORS.offWhite,
73+
},
74+
headerRight: () => <ConsoleHeaderButton />,
75+
headerStyle: {
76+
backgroundColor: COLORS.offWhite,
77+
borderBottomColor: COLORS.headerSeparator,
78+
borderBottomWidth: 1,
79+
},
80+
}}>
7381
<Stack.Screen
74-
key={name}
75-
name={name}
76-
getComponent={() => component}
77-
options={{ title: name }}
82+
name="Home"
83+
options={{ headerShown: false }}
84+
component={MainScreen}
7885
/>
79-
))}
80-
<Stack.Screen name="TouchableExample" component={TouchableExample} />
81-
</Stack.Navigator>
82-
</NavigationContainer>
86+
{(showLegacyVersion ? OLD_EXAMPLES : NEW_EXAMPLES)
87+
.flatMap(({ data }) => data)
88+
.flatMap(({ name, component }) => (
89+
<Stack.Screen
90+
key={name}
91+
name={name}
92+
getComponent={() => component}
93+
options={{ title: name }}
94+
/>
95+
))}
96+
<Stack.Screen
97+
name="TouchableExample"
98+
component={TouchableExample}
99+
/>
100+
</Stack.Navigator>
101+
</NavigationContainer>
102+
</View>
103+
</ConsoleModalProvider>
83104
</GestureHandlerRootView>
84105
);
85106

@@ -298,6 +319,9 @@ export default function App() {
298319
}
299320

300321
const styles = StyleSheet.create({
322+
root: {
323+
flex: 1,
324+
},
301325
container: {
302326
flex: 1,
303327
backgroundColor: COLORS.offWhite,

apps/common-app/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
import App from './App';
2+
import { installConsoleInterceptor } from './src/console';
3+
4+
installConsoleInterceptor();
25

36
export default App;

0 commit comments

Comments
 (0)