Last active
August 6, 2019 02:25
-
-
Save m4har/af08d92975893f65e42fa0019110023a to your computer and use it in GitHub Desktop.
kalo banyak component view di rn, pasti navigasinya agak lama
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
import React, { PureComponent } from 'react' | |
import { View, ViewPropTypes, Animated } from 'react-native' | |
import { withNavigationFocus } from 'react-navigation' | |
// import PropTypes from 'prop-types'; | |
class LazyView extends PureComponent { | |
state = { | |
show: false, | |
refresh: false | |
}; | |
constructor (props) { | |
super(props) | |
this.fadeAnimation = new Animated.Value(0) | |
setTimeout(() => { | |
this.setState({ show: true }) | |
Animated.timing(this.fadeAnimation, { | |
toValue: 1, | |
duration: 500, | |
useNativeDriver: true | |
}).start() | |
}, 1) | |
} | |
componentDidMount () { | |
// setTimeout(() => { | |
// this.setState({ show: true }) | |
// Animated.timing(this.fadeAnimation, { | |
// toValue: 1, | |
// duration: 500, | |
// useNativeDriver: true | |
// }).start() | |
// }, 1) | |
} | |
// componentDidUpdate(prevProps) { | |
// if(this.state.refresh){ | |
// if (prevProps.isFocused !== this.props.isFocused){ | |
// setTimeout(() => { | |
// this.setState({ show: true, refresh:false }); | |
// setTimeout(() => { | |
// this.setState({ show: true }) | |
// Animated.timing(this.fadeAnimation, { | |
// toValue: 1, | |
// duration: 500, | |
// useNativeDriver: true | |
// }).start() | |
// }, 1); | |
// }, 1); | |
// } | |
// } | |
// if(!this.props.isFocused){ | |
// setTimeout(() => { | |
// this.setState({ show: false, refresh:true }); | |
// }, 1); | |
// } | |
// } | |
render () { | |
const { show } = this.state | |
const { children, style } = this.props | |
return <>{show ? <Animated.View style={[style, { opacity: this.fadeAnimation, width: '100%' }]}>{children}</Animated.View> : null}</> | |
} | |
} | |
LazyView.propTypes = { | |
style: ViewPropTypes.style | |
} | |
export default withNavigationFocus(LazyView) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment