react-native-display
This module brings "Display: none" (css style) to turn on/off components from render. Using this module will improve your app performance and appearance with the enter/exit animations.
Installation
$ npm install react-native-display --save
Dependencies
Usage
;
Then, easy as:
<Display enable=thisstateenable> <Text> My custom components </Text></Display>
Properties
enter/exit
props using react-native-animatable for animation name.
Prop | Description | Default |
---|---|---|
enable |
true to render. false to not render. |
true |
defaultDuration |
Default duration for enter and exit animations. | 250 |
enterDuration |
Duration for enter animation. | 250 |
exitDuration |
Duration for exit animation. | 250 |
enter |
Animation name to run when render (enable=true). Example: enter='fadeIn' |
None |
exit |
Animation name to run when not render (enable=false). Example: exit='fadeOut' |
None |
style |
Same react-native style for View . |
None |
keepAlive |
When enable=false If true components will hide only (componentWillUnmount() will not fire). If false components will not render at all. Use it on complex components or on modules that required init on everytime that they are mount (for example: react-native-camera). |
false |
Using inspector to validate that after exit animation component will not render:
Full example:
;; ; { superprops; thisstate = enable: true; } { let toggle = !thisstateenable; this; } { return <View> <View style=stylesbutton> <Button onPress=thistoggleDisplay title="Toggle display" color="#34495e" accessibilityLabel="Toggle display for show/hide circles" /> </View> <View style=stylescenter> <Display enable=thisstateenable enterDuration=500 exitDuration=250 exit="fadeOutLeft" enter="fadeInLeft" > <View style=stylescircle backgroundColor: '#2ecc71' /> </Display> <Display enable=thisstateenable enterDuration=500 exitDuration=250 exit="fadeOutDown" enter="fadeInUp" > <View style=stylescircle backgroundColor: '#9b59b6' /> </Display> <Display enable=thisstateenable enterDuration=500 exitDuration=250 exit="fadeOutRight" enter="fadeInRight" > <View style=stylescircle backgroundColor: '#3498db' /> </Display> </View> </View> ; } const styles = button: padding: 10 margin: 15 center: flexDirection: 'row' justifyContent: 'space-between' alignItems: 'center' circle: borderRadius: 50 height: 100 width: 100 margin: 15 AppRegistry;
Result:
TODO:
- On start animation done event
- On exit animation done event