You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
10 KiB

{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport { EventEmitter } from 'expo-modules-core';\nimport React, { useEffect, useState, useRef, useMemo } from 'react';\nimport Animated from \"react-native-web/dist/exports/Animated\";\nimport StyleSheet from \"react-native-web/dist/exports/StyleSheet\";\nimport Text from \"react-native-web/dist/exports/Text\";\nimport Platform from \"react-native-web/dist/exports/Platform\";\nimport View from \"react-native-web/dist/exports/View\";\nimport DevLoadingViewNativeModule from \"./DevLoadingViewNativeModule\";\nimport { getInitialSafeArea } from \"./getInitialSafeArea\";\nexport default function DevLoadingView() {\n var _useState = useState('Refreshing...'),\n _useState2 = _slicedToArray(_useState, 2),\n message = _useState2[0],\n setMessage = _useState2[1];\n var _useState3 = useState(false),\n _useState4 = _slicedToArray(_useState3, 2),\n isDevLoading = _useState4[0],\n setIsDevLoading = _useState4[1];\n var _useState5 = useState(false),\n _useState6 = _slicedToArray(_useState5, 2),\n isAnimating = _useState6[0],\n setIsAnimating = _useState6[1];\n var translateY = useRef(new Animated.Value(0)).current;\n var emitter = useMemo(function () {\n try {\n return new EventEmitter(DevLoadingViewNativeModule);\n } catch (error) {\n throw new Error('Failed to instantiate native emitter in `DevLoadingView` because the native module `DevLoadingView` is undefined: ' + error.message);\n }\n }, []);\n useEffect(function () {\n if (!emitter) return;\n function handleShowMessage(event) {\n setMessage(event.message);\n translateY.setValue(0);\n setIsDevLoading(true);\n }\n function handleHide() {\n setIsAnimating(true);\n setIsDevLoading(false);\n Animated.timing(translateY, {\n toValue: 150,\n delay: 1000,\n duration: 350,\n useNativeDriver: Platform.OS !== 'web'\n }).start(function (_ref) {\n var finished = _ref.finished;\n if (finished) {\n setIsAnimating(false);\n translateY.setValue(0);\n }\n });\n }\n var showMessageSubscription = emitter.addListener('devLoadingView:showMessage', handleShowMessage);\n var hideSubscription = emitter.addListener('devLoadingView:hide', handleHide);\n return function cleanup() {\n showMessageSubscription.remove();\n hideSubscription.remove();\n };\n }, [translateY, emitter]);\n if (!isDevLoading && !isAnimating) {\n return null;\n }\n return React.createElement(Animated.View, {\n style: [styles.animatedContainer, {\n transform: [{\n translateY: translateY\n }]\n }],\n pointerEvents: \"none\"\n }, React.createElement(View, {\n style: styles.banner\n }, React.createElement(View, {\n style: styles.contentContainer\n }, React.createElement(View, {\n style: {\n flexDirection: 'row'\n }\n }, React.createElement(Text, {\n style: styles.text\n }, message)), React.createElement(View, {\n style: {\n flex: 1\n }\n }, React.createElement(Text, {\n style: styles.subtitle\n }, isDevLoading ? 'Using Fast Refresh' : \"Don't see your changes? Reload the app\")))));\n}\nvar styles = StyleSheet.create({\n animatedContainer: {\n position: 'absolute',\n bottom: 0,\n left: 0,\n right: 0,\n zIndex: 42\n },\n banner: {\n flex: 1,\n overflow: 'visible',\n backgroundColor: 'rgba(0,0,0,0.75)',\n paddingBottom: getInitialSafeArea().bottom\n },\n contentContainer: {\n flex: 1,\n paddingTop: 10,\n paddingBottom: 5,\n alignItems: 'center',\n justifyContent: 'center',\n textAlign: 'center'\n },\n text: {\n color: '#fff',\n fontSize: 15\n },\n subtitle: {\n color: 'rgba(255,255,255,0.8)'\n }\n});","map":{"version":3,"sources":["../../src/environment/DevLoadingView.tsx"],"names":[],"mappings":";AAAA,SAAS,YAAY,QAAQ,mBAAmB;AAChD,OAAO,KAAK,IAAI,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,QAAQ,OAAO;AAAC;AAAA;AAAA;AAAA;AAAA;AAGpE,OAAO,0BAA0B;AACjC,SAAS,kBAAkB;AAE3B,eAAc,SAAU,cAAc,GAAA;EACpC,gBAA8B,QAAQ,CAAC,eAAe,CAAC;IAAA;IAAhD,OAAO;IAAE,UAAU;EAC1B,iBAAwC,QAAQ,CAAC,KAAK,CAAC;IAAA;IAAhD,YAAY;IAAE,eAAe;EACpC,iBAAsC,QAAQ,CAAC,KAAK,CAAC;IAAA;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CAAC;IACP,QAAQ,EAAE,SAAS;IACnB,eAAe,EAAE,kBAAkB;IACnC,aAAa,EAAE,kBAAkB,EAAE,CAAC;GACrC;EACD,gBAAgB,EAAE;IAChB,IAAI,EAAE,CAAC;IACP,UAAU,EAAE,EAAE;IACd,aAAa,EAAE,CAAC;IAChB,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,QAAQ;IACxB,SAAS,EAAE;GACZ;EACD,IAAI,EAAE;IACJ,KAAK,EAAE,MAAM;IACb,QAAQ,EAAE;GACX;EACD,QAAQ,EAAE;IACR,KAAK,EAAE;EACR;CACF,CAAC","sourcesContent":["import { EventEmitter } from 'expo-modules-core';\nimport React, { useEffect, useState, useRef, useMemo } from 'react';\nimport { Animated, StyleSheet, Text, Platform, View } from 'react-native';\n\nimport DevLoadingViewNativeModule from './DevLoadingViewNativeModule';\nimport { getInitialSafeArea } from './getInitialSafeArea';\n\nexport default function DevLoadingView() {\n const [message, setMessage] = useState('Refreshing...');\n const [isDevLoading, setIsDevLoading] = useState(false);\n const [isAnimating, setIsAnimating] = useState(false);\n const translateY = useRef(new Animated.Value(0)).current;\n const emitter = useMemo<EventEmitter>(() => {\n try {\n return new EventEmitter(DevLoadingViewNativeModule);\n } catch (error) {\n throw new Error(\n 'Failed to instantiate native emitter in `DevLoadingView` because the native module `DevLoadingView` is undefined: ' +\n error.message\n );\n }\n }, []);\n\n useEffect(() => {\n if (!emitter) return;\n\n function handleShowMessage(event: { message: string }) {\n setMessage(event.message);\n // TODO: if we show the refreshing banner and don't get a hide message\n // for 3 seconds, warn the user that it's taking a while and suggest\n // they reload\n\n translateY.setValue(0);\n setIsDevLoading(true);\n }\n\n function handleHide() {\n // TODO: if we showed the 'refreshing' banner less than 250ms ago, delay\n // switching to the 'finished' banner\n\n setIsAnimating(true);\n setIsDevLoading(false);\n Animated.timing(translateY, {\n toValue: 150,\n delay: 1000,\n duration: 350,\n useNativeDriver: Platform.OS !== 'web',\n }).start(({ finished }) => {\n if (finished) {\n setIsAnimating(false);\n translateY.setValue(0);\n }\n });\n }\n\n const showMessageSubscription = emitter.addListener(\n 'devLoadingView:showMessage',\n handleShowMessage\n );\n const hideSubscription = emitter.addListener('devLoadingView:hide', handleHide);\n\n return function cleanup() {\n showMessageSubscription.remove();\n hideSubscription.remove();\n };\n }, [translateY, emitter]);\n\n if (!isDevLoading && !isAnimating) {\n return null;\n }\n\n return (\n <Animated.View\n style={[styles.animatedContainer, { transform: [{ translateY }] }]}\n pointerEvents=\"none\">\n <View style={styles.banner}>\n <View style={styles.contentContainer}>\n <View style={{ flexDirection: 'row' }}>\n <Text style={styles.text}>{message}</Text>\n </View>\n\n <View style={{ flex: 1 }}>\n <Text style={styles.subtitle}>\n {isDevLoading ? 'Using Fast Refresh' : \"Don't see your changes? Reload the app\"}\n </Text>\n </View>\n </View>\n </View>\n </Animated.View>\n );\n}\n\nconst styles = StyleSheet.create({\n animatedContainer: {\n position: 'absolute',\n bottom: 0,\n left: 0,\n right: 0,\n zIndex: 42, // arbitrary\n },\n\n banner: {\n flex: 1,\n overflow: 'visible',\n backgroundColor: 'rgba(0,0,0,0.75)',\n paddingBottom: getInitialSafeArea().bottom,\n },\n contentContainer: {\n flex: 1,\n paddingTop: 10,\n paddingBottom: 5,\n alignItems: 'center',\n justifyContent: 'center',\n textAlign: 'center',\n },\n text: {\n color: '#fff',\n fontSize: 15,\n },\n subtitle: {\n color: 'rgba(255,255,255,0.8)',\n },\n});\n"],"sourceRoot":""},"metadata":{},"sourceType":"module"}