This repository has been archived by the owner on Feb 8, 2020. It is now read-only.
generated from satya164/typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use resource saving view for scenes. fixes #3
- Loading branch information
Showing
3 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* @flow */ | ||
|
||
import * as React from 'react'; | ||
import { Platform, StyleSheet, View } from 'react-native'; | ||
|
||
type Props = { | ||
isFocused: boolean, | ||
children: React.Node, | ||
style?: any, | ||
}; | ||
|
||
const FAR_FAR_AWAY = 3000; // this should be big enough to move the whole view out of its container | ||
|
||
export default class ResourceSavingScene extends React.Component<Props> { | ||
render() { | ||
const { isFocused, children, style, ...rest } = this.props; | ||
|
||
return ( | ||
<View | ||
style={[styles.container, style]} | ||
collapsable={false} | ||
removeClippedSubviews={ | ||
// On iOS, set removeClippedSubviews to true only when not focused | ||
// This is an workaround for a bug where the clipped view never re-appears | ||
Platform.OS === 'ios' ? !isFocused : true | ||
} | ||
pointerEvents={isFocused ? 'auto' : 'none'} | ||
{...rest} | ||
> | ||
<View style={isFocused ? styles.attached : styles.detached}> | ||
{children} | ||
</View> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
overflow: 'hidden', | ||
}, | ||
attached: { | ||
flex: 1, | ||
}, | ||
detached: { | ||
flex: 1, | ||
top: FAR_FAR_AWAY, | ||
}, | ||
}); |