1 line
7.7 KiB
Plaintext
1 line
7.7 KiB
Plaintext
{"version":3,"sources":["SafeAreaContext.tsx"],"names":["SafeAreaInsetsContext","React","createContext","displayName","SafeAreaFrameContext","SafeAreaProvider","children","initialMetrics","initialSafeAreaInsets","style","parentInsets","useParentSafeAreaInsets","parentFrame","useParentSafeAreaFrame","insets","setInsets","useState","frame","setFrame","x","y","width","Dimensions","get","height","onInsetsChange","useCallback","event","nativeEvent","nextFrame","nextInsets","bottom","left","right","top","styles","fill","StyleSheet","create","flex","useContext","useSafeAreaInsets","safeArea","Error","useSafeAreaFrame","withSafeAreaInsets","WrappedComponent","forwardRef","props","ref","useSafeArea","SafeAreaConsumer","Consumer","SafeAreaContext"],"mappings":";;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;AAGO,MAAMA,qBAAqB,GAAGC,KAAK,CAACC,aAAN,CACnC,IADmC,CAA9B;;AAGPF,qBAAqB,CAACG,WAAtB,GAAoC,uBAApC;AAEO,MAAMC,oBAAoB,GAAGH,KAAK,CAACC,aAAN,CAAiC,IAAjC,CAA7B;;AACPE,oBAAoB,CAACD,WAArB,GAAmC,sBAAnC;;AAYO,SAASE,gBAAT,CAA0B;AAC/BC,EAAAA,QAD+B;AAE/BC,EAAAA,cAF+B;AAG/BC,EAAAA,qBAH+B;AAI/BC,EAAAA;AAJ+B,CAA1B,EAKe;AAAA;;AACpB,QAAMC,YAAY,GAAGC,uBAAuB,EAA5C;AACA,QAAMC,WAAW,GAAGC,sBAAsB,EAA1C;AACA,QAAM,CAACC,MAAD,EAASC,SAAT,IAAsBd,KAAK,CAACe,QAAN,2CAC1BT,cAD0B,aAC1BA,cAD0B,uBAC1BA,cAAc,CAAEO,MADU,yEACAN,qBADA,yCACyBE,YADzB,uCACyC,IADzC,CAA5B;AAGA,QAAM,CAACO,KAAD,EAAQC,QAAR,IAAoBjB,KAAK,CAACe,QAAN,mCACxBT,cADwB,aACxBA,cADwB,uBACxBA,cAAc,CAAEU,KADQ,yEAEt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AAmC;AACxC,SAAOT,iBAAiB,EAAxB;AACD;AAED;;;;;AAGO,MAAMU,gBAAgB,GAAGnD,qBAAqB,CAACoD,QAA/C;AAEP;;;;;AAGO,MAAMC,eAAe,GAAGrD,qBAAxB","sourcesContent":["import * as React from 'react';\nimport { Dimensions, StyleProp, StyleSheet, ViewStyle } from 'react-native';\nimport NativeSafeAreaProvider from './NativeSafeAreaProvider';\nimport { EdgeInsets, InsetChangedEvent, Metrics, Rect } from './SafeArea.types';\n\nexport const SafeAreaInsetsContext = React.createContext<EdgeInsets | null>(\n null,\n);\nSafeAreaInsetsContext.displayName = 'SafeAreaInsetsContext';\n\nexport const SafeAreaFrameContext = React.createContext<Rect | null>(null);\nSafeAreaFrameContext.displayName = 'SafeAreaFrameContext';\n\nexport interface SafeAreaViewProps {\n children?: React.ReactNode;\n initialMetrics?: Metrics | null;\n /**\n * @deprecated\n */\n initialSafeAreaInsets?: EdgeInsets | null;\n style?: StyleProp<ViewStyle>;\n}\n\nexport function SafeAreaProvider({\n children,\n initialMetrics,\n initialSafeAreaInsets,\n style,\n}: SafeAreaViewProps) {\n const parentInsets = useParentSafeAreaInsets();\n const parentFrame = useParentSafeAreaFrame();\n const [insets, setInsets] = React.useState<EdgeInsets | null>(\n initialMetrics?.insets ?? initialSafeAreaInsets ?? parentInsets ?? null,\n );\n const [frame, setFrame] = React.useState<Rect>(\n initialMetrics?.frame ??\n parentFrame ?? {\n // Backwards compat so we render anyway if we don't have frame.\n x: 0,\n y: 0,\n width: Dimensions.get('window').width,\n height: Dimensions.get('window').height,\n },\n );\n const onInsetsChange = React.useCallback(\n (event: InsetChangedEvent) => {\n const {\n nativeEvent: { frame: nextFrame, insets: nextInsets },\n } = event;\n\n if (\n // Backwards compat with old native code that won't send frame.\n nextFrame &&\n (nextFrame.height !== frame.height ||\n nextFrame.width !== frame.width ||\n nextFrame.x !== frame.x ||\n nextFrame.y !== frame.y)\n ) {\n setFrame(nextFrame);\n }\n\n if (\n !insets ||\n nextInsets.bottom !== insets.bottom ||\n nextInsets.left !== insets.left ||\n nextInsets.right !== insets.right ||\n nextInsets.top !== insets.top\n ) {\n setInsets(nextInsets);\n }\n },\n [frame, insets],\n );\n\n return (\n <NativeSafeAreaProvider\n style={[styles.fill, style]}\n onInsetsChange={onInsetsChange}\n >\n {insets != null ? (\n <SafeAreaFrameContext.Provider value={frame}>\n <SafeAreaInsetsContext.Provider value={insets}>\n {children}\n </SafeAreaInsetsContext.Provider>\n </SafeAreaFrameContext.Provider>\n ) : null}\n </NativeSafeAreaProvider>\n );\n}\n\nconst styles = StyleSheet.create({\n fill: { flex: 1 },\n});\n\nfunction useParentSafeAreaInsets(): EdgeInsets | null {\n return React.useContext(SafeAreaInsetsContext);\n}\n\nfunction useParentSafeAreaFrame(): Rect | null {\n return React.useContext(SafeAreaFrameContext);\n}\n\nexport function useSafeAreaInsets(): EdgeInsets {\n const safeArea = React.useContext(SafeAreaInsetsContext);\n if (safeArea == null) {\n throw new Error(\n 'No safe area insets value available. Make sure you are rendering `<SafeAreaProvider>` at the top of your app.',\n );\n }\n return safeArea;\n}\n\nexport function useSafeAreaFrame(): Rect {\n const frame = React.useContext(SafeAreaFrameContext);\n if (frame == null) {\n throw new Error(\n 'No safe area frame value available. Make sure you are rendering `<SafeAreaProvider>` at the top of your app.',\n );\n }\n return frame;\n}\n\nexport function withSafeAreaInsets<T>(\n WrappedComponent: React.ComponentType<T>,\n) {\n return React.forwardRef((props: T, ref: React.Ref<T>) => (\n <SafeAreaConsumer>\n {(insets) => <WrappedComponent {...props} insets={insets} ref={ref} />}\n </SafeAreaConsumer>\n ));\n}\n\n/**\n * @deprecated\n */\nexport function useSafeArea(): EdgeInsets {\n return useSafeAreaInsets();\n}\n\n/**\n * @deprecated\n */\nexport const SafeAreaConsumer = SafeAreaInsetsContext.Consumer;\n\n/**\n * @deprecated\n */\nexport const SafeAreaContext = SafeAreaInsetsContext;\n"]} |