Skip to content

Instantly share code, notes, and snippets.

@m4har
Last active August 6, 2019 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4har/af08d92975893f65e42fa0019110023a to your computer and use it in GitHub Desktop.
Save m4har/af08d92975893f65e42fa0019110023a to your computer and use it in GitHub Desktop.
kalo banyak component view di rn, pasti navigasinya agak lama
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