|
| 1 | +import React, { useCallback, useState } from "react"; |
| 2 | +import type { NativeSyntheticEvent } from "react-native"; |
| 3 | +import { |
| 4 | + ScrollView, |
| 5 | + StatusBar, |
| 6 | + Text, |
| 7 | + useColorScheme, |
| 8 | + View, |
| 9 | +} from "react-native"; |
| 10 | +import { Feature } from "./Feature"; |
| 11 | +import { LocalStorageStatus } from "./LocalStorage"; |
| 12 | +import { RemoteDebugging } from "./RemoteDebugging"; |
| 13 | +import { SafeAreaView } from "./SafeAreaView"; |
| 14 | +import { Separator } from "./Separator"; |
| 15 | +import { |
| 16 | + getHermesVersion, |
| 17 | + isBridgeless, |
| 18 | + isConcurrentReactEnabled, |
| 19 | + isFabricInstance, |
| 20 | + ReactNativeVersion, |
| 21 | +} from "./core"; |
| 22 | +import { useStyles } from "./styles"; |
| 23 | + |
| 24 | +declare global { |
| 25 | + export const RN$Bridgeless: boolean; |
| 26 | +} |
| 27 | + |
| 28 | +type AppProps = { |
| 29 | + concurrentRoot?: boolean; |
| 30 | +}; |
| 31 | + |
| 32 | +function useIsFabricComponent() { |
| 33 | + const [isFabric, setIsFabric] = useState(isBridgeless()); |
| 34 | + const setter = useCallback( |
| 35 | + ({ currentTarget }: NativeSyntheticEvent<unknown>) => { |
| 36 | + setIsFabric(isFabricInstance(currentTarget)); |
| 37 | + }, |
| 38 | + [setIsFabric] |
| 39 | + ); |
| 40 | + return [isFabric, setter] as const; |
| 41 | +} |
| 42 | + |
| 43 | +export function App(props: AppProps): React.ReactElement<AppProps> { |
| 44 | + const isDarkMode = useColorScheme() === "dark"; |
| 45 | + const styles = useStyles(); |
| 46 | + const [isFabric, setIsFabric] = useIsFabricComponent(); |
| 47 | + |
| 48 | + return ( |
| 49 | + <SafeAreaView style={styles.body}> |
| 50 | + <StatusBar barStyle={isDarkMode ? "light-content" : "dark-content"} /> |
| 51 | + <ScrollView |
| 52 | + contentInsetAdjustmentBehavior="automatic" |
| 53 | + onLayout={setIsFabric} |
| 54 | + style={styles.body} |
| 55 | + > |
| 56 | + <Text style={styles.title}>Welcome to React Native</Text> |
| 57 | + <RemoteDebugging /> |
| 58 | + <LocalStorageStatus /> |
| 59 | + <View style={styles.group}> |
| 60 | + <Feature value={ReactNativeVersion.getVersionString()}> |
| 61 | + React Native |
| 62 | + </Feature> |
| 63 | + <Separator /> |
| 64 | + <Feature value={getHermesVersion() ?? "JSC"}>JS Engine</Feature> |
| 65 | + <Separator /> |
| 66 | + <Feature value={isFabric}>Fabric</Feature> |
| 67 | + <Separator /> |
| 68 | + <Feature value={isConcurrentReactEnabled(props, isFabric)}> |
| 69 | + Concurrent React |
| 70 | + </Feature> |
| 71 | + <Separator /> |
| 72 | + <Feature value={isBridgeless()}>Bridgeless</Feature> |
| 73 | + </View> |
| 74 | + </ScrollView> |
| 75 | + </SafeAreaView> |
| 76 | + ); |
| 77 | +} |
0 commit comments