UNPKG

2.56 kBJavaScriptView Raw
1function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
3import * as React from 'react';
4import { Platform, StyleSheet, View } from 'react-native';
5import { Screen, screensEnabled // @ts-ignore
6, shouldUseActivityState } from 'react-native-screens';
7const FAR_FAR_AWAY = 30000; // this should be big enough to move the whole view out of its container
8
9export default class ResourceSavingScene extends React.Component {
10 render() {
11 // react-native-screens is buggy on web
12 if ((screensEnabled === null || screensEnabled === void 0 ? void 0 : screensEnabled()) && this.props.enabled && Platform.OS !== 'web') {
13 const {
14 isVisible,
15 ...rest
16 } = this.props;
17
18 if (shouldUseActivityState) {
19 return (
20 /*#__PURE__*/
21 // @ts-expect-error: there was an `active` prop and no `activityState` in older version and stackPresentation was required
22 React.createElement(Screen, _extends({
23 activityState: isVisible ? 2 : 0
24 }, rest))
25 );
26 } else {
27 return (
28 /*#__PURE__*/
29 // @ts-expect-error: there was an `active` prop and no `activityState` in older version and stackPresentation was required
30 React.createElement(Screen, _extends({
31 active: isVisible ? 1 : 0
32 }, rest))
33 );
34 }
35 }
36
37 const {
38 isVisible,
39 children,
40 style,
41 ...rest
42 } = this.props;
43 return /*#__PURE__*/React.createElement(View, _extends({
44 style: [styles.container, Platform.OS === 'web' ? {
45 display: isVisible ? 'flex' : 'none'
46 } : null, style],
47 collapsable: false,
48 removeClippedSubviews: // On iOS, set removeClippedSubviews to true only when not focused
49 // This is an workaround for a bug where the clipped view never re-appears
50 Platform.OS === 'ios' ? !isVisible : true,
51 pointerEvents: isVisible ? 'auto' : 'none'
52 }, rest), /*#__PURE__*/React.createElement(View, {
53 style: isVisible ? styles.attached : styles.detached
54 }, children));
55 }
56
57}
58const styles = StyleSheet.create({
59 container: {
60 flex: 1,
61 overflow: 'hidden'
62 },
63 attached: {
64 flex: 1
65 },
66 detached: {
67 flex: 1,
68 top: FAR_FAR_AWAY
69 }
70});
71//# sourceMappingURL=ResourceSavingScene.js.map
\No newline at end of file