This file contains hidden or 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
class NamesList extends React.PureComponent { | |
static getDerivedStateFromProps(nextProps, prevState) { | |
const letters = extractLetters(nextProps.data); | |
return { | |
sections: letters.map(letter => { | |
const data = nextProps.data.filter(item => item.startsWith(letter)); | |
return { | |
letter, | |
data, | |
renderItem: ({ item }) => ( |
This file contains hidden or 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 from 'react'; | |
import { View, Text, AppState } from 'react-native'; | |
const SIZE = 1000000; | |
export default class DetailsScreen extends React.Component { | |
memory = new Array(SIZE).join('|'); | |
interval = null; | |
state = { count: 1 }; |
This file contains hidden or 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
AppState.addEventListener('change', nextAppState => { | |
if (nextAppState === 'active') { | |
this.interval = setInterval(this.refresh, 1000); | |
} else { | |
clearInterval(this.interval); | |
} | |
}); |
This file contains hidden or 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
componentDidMount() { | |
let { countdown, hours, mins, sec } = this.props; | |
if (countdown) { | |
this._interval = setInterval(() => { | |
sec -= 1; | |
if (sec < 0) { | |
sec = 59; | |
mins -= 1; | |
} | |
if (mins < 0) { |
This file contains hidden or 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
componentDidUpdate(prevProps) { | |
const clockPropsHasChanged = ['hours', 'mins', 'sec', 'countdown'].some( | |
prop => this.props[prop] !== prevProps[prop] | |
); | |
if (clockPropsHasChanged) { | |
clearInterval(this._interval); | |
let { countdown, hours, mins, sec } = this.props; | |
if (countdown) { | |
this._interval = setInterval(() => { | |
sec -= 1; |
This file contains hidden or 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
class Composer extends Component { | |
state = { showAccessory: false } | |
componentDidMount() { | |
Keyboard.addListener('keyboardDidShow', () => this.setState({ showAccessory: true })); | |
Keyboard.addListener('keyboardDidHide', () => this.setState({ showAccessory: false })); | |
} | |
render() { | |
return ( | |
<View> |
This file contains hidden or 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
class Composer extends Component { | |
state = { showAccessory: false }; | |
componentDidMount() { | |
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', () => | |
this.setState({ showAccessory: true }) | |
); | |
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', () => | |
this.setState({ showAccessory: false }) | |
); |
This file contains hidden or 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, { Component } from 'react'; | |
import { StyleSheet, View } from 'react-native'; | |
import { PanGestureHandler, State } from 'react-native-gesture-handler'; | |
import Animated from 'react-native-reanimated'; | |
const { | |
event, | |
Value, | |
cond, |
This file contains hidden or 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
render() { | |
return ( | |
<PanGestureHandler | |
onGestureEvent={this._onGestureEvent} | |
onHandlerStateChange={this._onGestureEvent}> | |
<Animated.View | |
style={[ | |
styles.box, | |
{ | |
transform: [{ translateX: this._transX }], |
This file contains hidden or 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
const { | |
event, | |
Value, | |
} = Animated; |