Back out "Remove deprecated lifecycles usage"
Summary: Changelog: [General][Changed] REVERT: createAnimatedComponent: removed deprecated lifecycles usage Original commit changeset: 04d016b30ae0 Reviewed By: JoshuaGross Differential Revision: D27053061 fbshipit-source-id: 6bb50da0a773070a979e7c52957a375b20c7c609
This commit is contained in:
Родитель
903351f22e
Коммит
6333c15fa2
|
@ -53,16 +53,8 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
|
||||||
);
|
);
|
||||||
|
|
||||||
class AnimatedComponent extends React.Component<Object> {
|
class AnimatedComponent extends React.Component<Object> {
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this._waitForUpdate();
|
|
||||||
this._attachProps(this.props);
|
|
||||||
this._lastProps = this.props;
|
|
||||||
}
|
|
||||||
|
|
||||||
_component: any; // TODO T53738161: flow type this, and the whole file
|
_component: any; // TODO T53738161: flow type this, and the whole file
|
||||||
_invokeAnimatedPropsCallbackOnMount: boolean = false;
|
_invokeAnimatedPropsCallbackOnMount: boolean = false;
|
||||||
_lastProps: Object;
|
|
||||||
_prevComponent: any;
|
_prevComponent: any;
|
||||||
_propsAnimated: AnimatedProps;
|
_propsAnimated: AnimatedProps;
|
||||||
_eventDetachers: Array<Function> = [];
|
_eventDetachers: Array<Function> = [];
|
||||||
|
@ -182,6 +174,10 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
|
||||||
_attachProps(nextProps) {
|
_attachProps(nextProps) {
|
||||||
const oldPropsAnimated = this._propsAnimated;
|
const oldPropsAnimated = this._propsAnimated;
|
||||||
|
|
||||||
|
if (nextProps === oldPropsAnimated) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._propsAnimated = new AnimatedProps(
|
this._propsAnimated = new AnimatedProps(
|
||||||
nextProps,
|
nextProps,
|
||||||
this._animatedPropsCallback,
|
this._animatedPropsCallback,
|
||||||
|
@ -223,11 +219,6 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
|
||||||
});
|
});
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this._lastProps !== this.props) {
|
|
||||||
this._waitForUpdate();
|
|
||||||
this._attachProps(this.props);
|
|
||||||
this._lastProps = this.props;
|
|
||||||
}
|
|
||||||
const {style = {}, ...props} = this._propsAnimated.__getValue() || {};
|
const {style = {}, ...props} = this._propsAnimated.__getValue() || {};
|
||||||
const {style: passthruStyle = {}, ...passthruProps} =
|
const {style: passthruStyle = {}, ...passthruProps} =
|
||||||
this.props.passthroughAnimatedPropExplicitValues || {};
|
this.props.passthroughAnimatedPropExplicitValues || {};
|
||||||
|
@ -272,6 +263,11 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillMount() {
|
||||||
|
this._waitForUpdate();
|
||||||
|
this._attachProps(this.props);
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (this._invokeAnimatedPropsCallbackOnMount) {
|
if (this._invokeAnimatedPropsCallbackOnMount) {
|
||||||
this._invokeAnimatedPropsCallbackOnMount = false;
|
this._invokeAnimatedPropsCallbackOnMount = false;
|
||||||
|
@ -283,6 +279,11 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
|
||||||
this._markUpdateComplete();
|
this._markUpdateComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNSAFE_componentWillReceiveProps(newProps) {
|
||||||
|
this._waitForUpdate();
|
||||||
|
this._attachProps(newProps);
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
if (this._component !== this._prevComponent) {
|
if (this._component !== this._prevComponent) {
|
||||||
this._propsAnimated.setNativeView(this._component);
|
this._propsAnimated.setNativeView(this._component);
|
||||||
|
|
|
@ -12,14 +12,7 @@
|
||||||
|
|
||||||
const RNTesterButton = require('../../components/RNTesterButton');
|
const RNTesterButton = require('../../components/RNTesterButton');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const {
|
const {Animated, Easing, StyleSheet, Text, View} = require('react-native');
|
||||||
Animated,
|
|
||||||
Easing,
|
|
||||||
Pressable,
|
|
||||||
StyleSheet,
|
|
||||||
Text,
|
|
||||||
View,
|
|
||||||
} = require('react-native');
|
|
||||||
|
|
||||||
import type {RNTesterExampleModuleItem} from '../../types/RNTesterTypes';
|
import type {RNTesterExampleModuleItem} from '../../types/RNTesterTypes';
|
||||||
|
|
||||||
|
@ -90,17 +83,11 @@ exports.examples = ([
|
||||||
}
|
}
|
||||||
|
|
||||||
type Props = $ReadOnly<{||}>;
|
type Props = $ReadOnly<{||}>;
|
||||||
type State = {|
|
type State = {|show: boolean|};
|
||||||
disabled: boolean,
|
|
||||||
pressCount: number,
|
|
||||||
show: boolean,
|
|
||||||
|};
|
|
||||||
class FadeInExample extends React.Component<Props, State> {
|
class FadeInExample extends React.Component<Props, State> {
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
disabled: true,
|
|
||||||
pressCount: 0,
|
|
||||||
show: true,
|
show: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -110,35 +97,15 @@ exports.examples = ([
|
||||||
<RNTesterButton
|
<RNTesterButton
|
||||||
testID="toggle-button"
|
testID="toggle-button"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
this.setState(state => ({pressCount: 0, show: !state.show}));
|
this.setState(state => ({show: !state.show}));
|
||||||
}}>
|
}}>
|
||||||
Press to {this.state.show ? 'Hide' : 'Show'}
|
Press to {this.state.show ? 'Hide' : 'Show'}
|
||||||
</RNTesterButton>
|
</RNTesterButton>
|
||||||
<RNTesterButton
|
|
||||||
testID="toggle-pressable"
|
|
||||||
onPress={() => {
|
|
||||||
this.setState(state => ({disabled: !state.disabled}));
|
|
||||||
}}>
|
|
||||||
Press to {this.state.disabled ? 'Enable' : 'Disable'}
|
|
||||||
</RNTesterButton>
|
|
||||||
{this.state.show && (
|
{this.state.show && (
|
||||||
<FadeInView>
|
<FadeInView>
|
||||||
<Pressable
|
<View testID="fade-in-view" style={styles.content}>
|
||||||
testID="fade-in-view"
|
<Text>FadeInView</Text>
|
||||||
style={styles.content}
|
</View>
|
||||||
disabled={this.state.disabled}
|
|
||||||
onPress={() => {
|
|
||||||
this.setState(state => ({
|
|
||||||
pressCount: this.state.pressCount + 1,
|
|
||||||
}));
|
|
||||||
}}>
|
|
||||||
<Text>
|
|
||||||
FadeInView
|
|
||||||
{this.state.disabled
|
|
||||||
? ''
|
|
||||||
: ` Pressable: ${this.state.pressCount}`}
|
|
||||||
</Text>
|
|
||||||
</Pressable>
|
|
||||||
</FadeInView>
|
</FadeInView>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче