Ran rename-unsafe-lifecycles codemod on xplat/js

Reviewed By: trueadm

Differential Revision: D6889214

fbshipit-source-id: e815cda4b09f3650ae3b0b9a44ae6f5fcb48fe25
This commit is contained in:
Brian Vaughn 2018-02-08 10:26:45 -08:00 committed by Facebook Github Bot
parent fa334ce464
commit 6f007e8957
53 changed files with 75 additions and 66 deletions

View File

@ -30,7 +30,7 @@ var ReactContentSizeUpdateTest = createReactClass({
mixins: [Subscribable.Mixin,
TimerMixin],
componentWillMount: function() {
UNSAFE_componentWillMount: function() {
this.addListenerOn(
RCTNativeAppEventEmitter,
'rootViewDidChangeIntrinsicSize',

View File

@ -27,7 +27,7 @@ var SizeFlexibilityUpdateTest = createReactClass({
displayName: 'SizeFlexibilityUpdateTest',
mixins: [Subscribable.Mixin],
componentWillMount: function() {
UNSAFE_componentWillMount: function() {
this.addListenerOn(
RCTNativeAppEventEmitter,
'rootViewDidChangeIntrinsicSize',

View File

@ -94,11 +94,11 @@ describe('Animated tests', () => {
opacity: anim,
},
};
c.componentWillMount();
c.UNSAFE_componentWillMount();
expect(anim.__detach).not.toBeCalled();
c._component = {};
c.componentWillReceiveProps({
c.UNSAFE_componentWillReceiveProps({
style: {
opacity: anim,
},
@ -120,7 +120,7 @@ describe('Animated tests', () => {
opacity: anim,
},
};
c.componentWillMount();
c.UNSAFE_componentWillMount();
Animated.timing(anim, {toValue: 10, duration: 1000}).start(callback);
c._component = {};

View File

@ -29,7 +29,7 @@ const NativeAnimatedHelper = require('NativeAnimatedHelper');
function createAndMountComponent(ComponentClass, props) {
const component = new ComponentClass();
component.props = props;
component.componentWillMount();
component.UNSAFE_componentWillMount();
// Simulate that refs were set.
component._component = {};
component.componentDidMount();

View File

@ -42,7 +42,7 @@ function createAnimatedComponent(Component: any): any {
this._component.setNativeProps(props);
}
componentWillMount() {
UNSAFE_componentWillMount() {
this._attachProps(this.props);
}
@ -127,7 +127,7 @@ function createAnimatedComponent(Component: any): any {
oldPropsAnimated && oldPropsAnimated.__detach();
}
componentWillReceiveProps(newProps) {
UNSAFE_componentWillReceiveProps(newProps) {
this._attachProps(newProps);
}

View File

@ -133,7 +133,7 @@ const KeyboardAvoidingView = createReactClass({
this.frame = event.nativeEvent.layout;
},
componentWillUpdate(nextProps: Object, nextState: Object, nextContext?: Object): void {
UNSAFE_componentWillUpdate(nextProps: Object, nextState: Object, nextContext?: Object): void {
if (nextState.bottom === this.state.bottom &&
this.props.behavior === 'height' &&
nextProps.behavior === 'height') {
@ -143,7 +143,7 @@ const KeyboardAvoidingView = createReactClass({
}
},
componentWillMount() {
UNSAFE_componentWillMount() {
if (Platform.OS === 'ios') {
this.subscriptions = [
Keyboard.addListener('keyboardWillChangeFrame', this._onKeyboardChange),

View File

@ -23,7 +23,7 @@ var LazyRenderer = createReactClass({
render: PropTypes.func.isRequired,
},
componentWillMount: function(): void {
UNSAFE_componentWillMount: function(): void {
this.setState({
_lazyRender : true,
});

View File

@ -515,7 +515,7 @@ var NavigatorIOS = createReactClass({
navigator: (undefined: ?Object),
componentWillMount: function() {
UNSAFE_componentWillMount: function() {
// Precompute a pack of callbacks that's frequently generated and passed to
// instances.
this.navigator = {

View File

@ -66,7 +66,7 @@ class PickerAndroid extends React.Component<{
};
}
componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
this.setState(this._stateFromProps(nextProps));
}

View File

@ -41,7 +41,7 @@ var PickerIOS = createReactClass({
return this._stateFromProps(this.props);
},
componentWillReceiveProps: function(nextProps) {
UNSAFE_componentWillReceiveProps: function(nextProps) {
this.setState(this._stateFromProps(nextProps));
},

View File

@ -548,7 +548,7 @@ const ScrollResponderMixin = {
*
* The `keyboardWillShow` is called before input focus.
*/
componentWillMount: function() {
UNSAFE_componentWillMount: function() {
const {keyboardShouldPersistTaps} = this.props;
warning(
typeof keyboardShouldPersistTaps !== 'boolean',

View File

@ -510,7 +510,7 @@ const ScrollView = createReactClass({
};
},
componentWillMount: function() {
UNSAFE_componentWillMount: function() {
this._scrollAnimatedValue = new Animated.Value(this.props.contentOffset ? this.props.contentOffset.y : 0);
this._scrollAnimatedValue.setOffset(this.props.contentInset ? this.props.contentInset.top : 0);
this._stickyHeaderRefs = new Map();

View File

@ -25,7 +25,7 @@ var Subscribable = {};
Subscribable.Mixin = {
componentWillMount: function() {
UNSAFE_componentWillMount: function() {
this._subscribableSubscriptions = [];
},

View File

@ -102,13 +102,13 @@ class TabBarItemIOS extends React.Component {
hasBeenSelected: false,
};
componentWillMount() {
UNSAFE_componentWillMount() {
if (this.props.selected) {
this.setState({hasBeenSelected: true});
}
}
componentWillReceiveProps(nextProps: { selected?: boolean }) {
UNSAFE_componentWillReceiveProps(nextProps: { selected?: boolean }) {
if (this.state.hasBeenSelected || nextProps.selected) {
this.setState({hasBeenSelected: true});
}

View File

@ -203,7 +203,7 @@ const TouchableHighlight = createReactClass({
clearTimeout(this._hideTimeout);
},
componentWillReceiveProps: function(nextProps) {
UNSAFE_componentWillReceiveProps: function(nextProps) {
ensurePositiveDelayProps(nextProps);
},

View File

@ -147,7 +147,7 @@ var TouchableNativeFeedback = createReactClass({
ensurePositiveDelayProps(this.props);
},
componentWillReceiveProps: function(nextProps) {
UNSAFE_componentWillReceiveProps: function(nextProps) {
ensurePositiveDelayProps(nextProps);
},

View File

@ -158,7 +158,7 @@ var TouchableOpacity = createReactClass({
ensurePositiveDelayProps(this.props);
},
componentWillReceiveProps: function(nextProps) {
UNSAFE_componentWillReceiveProps: function(nextProps) {
ensurePositiveDelayProps(nextProps);
},

View File

@ -122,7 +122,7 @@ const TouchableWithoutFeedback = createReactClass({
ensurePositiveDelayProps(this.props);
},
componentWillReceiveProps: function(nextProps: Object) {
UNSAFE_componentWillReceiveProps: function(nextProps: Object) {
ensurePositiveDelayProps(nextProps);
},

View File

@ -247,7 +247,7 @@ class WebView extends React.Component {
startInLoadingState: true,
};
componentWillMount() {
UNSAFE_componentWillMount() {
if (this.props.startInLoadingState) {
this.setState({viewState: WebViewState.LOADING});
}

View File

@ -410,7 +410,7 @@ class WebView extends React.Component {
startInLoadingState: true,
};
componentWillMount() {
UNSAFE_componentWillMount() {
if (this.props.startInLoadingState) {
this.setState({viewState: WebViewState.LOADING});
}

View File

@ -129,7 +129,7 @@ class Incremental extends React.Component<Props, State> {
return ctx.groupId + ':' + this._incrementId + '-' + this.props.name;
}
componentWillMount() {
UNSAFE_componentWillMount() {
const ctx = this.context.incrementalGroup;
if (!ctx) {
return;

View File

@ -37,7 +37,7 @@ import type {Props, Context} from 'Incremental';
class IncrementalGroup extends React.Component<Props & {disabled?: boolean}> {
context: Context;
_groupInc: string;
componentWillMount() {
UNSAFE_componentWillMount() {
this._groupInc = `g${++_groupCounter}-`;
DEBUG && infoLog(
'create IncrementalGroup with id ' + this.getGroupId()

View File

@ -105,7 +105,7 @@ class SwipeableListView extends React.Component<Props, State> {
};
}
componentWillReceiveProps(nextProps: Props): void {
UNSAFE_componentWillReceiveProps(nextProps: Props): void {
if (this.state.dataSource.getDataSource() !== nextProps.dataSource.getDataSource()) {
this.setState({
dataSource: nextProps.dataSource,

View File

@ -125,7 +125,7 @@ const SwipeableRow = createReactClass({
};
},
componentWillMount(): void {
UNSAFE_componentWillMount(): void {
this._panResponder = PanResponder.create({
onMoveShouldSetPanResponderCapture: this._handleMoveShouldSetPanResponderCapture,
onPanResponderGrant: this._handlePanResponderGrant,
@ -149,7 +149,7 @@ const SwipeableRow = createReactClass({
}
},
componentWillReceiveProps(nextProps: Object): void {
UNSAFE_componentWillReceiveProps(nextProps: Object): void {
/**
* We do not need an "animateOpen(noCallback)" because this animation is
* handled internally by this component.

View File

@ -243,7 +243,7 @@ class WindowedListView extends React.Component<Props, State> {
DEBUG && infoLog(' knope');
return false;
}
componentWillReceiveProps() {
UNSAFE_componentWillReceiveProps() {
this._computeRowsToRenderBatcher.schedule();
}
_onMomentumScrollEnd = (e: Object) => {
@ -624,7 +624,7 @@ class CellRenderer extends React.Component<CellProps> {
_perfUpdateID: number = 0;
_asyncCookie: any;
_includeInLayoutLatch: boolean = false;
componentWillMount() {
UNSAFE_componentWillMount() {
if (this.props.asyncRowPerfEventName) {
this._perfUpdateID = g_perf_update_id++;
this._asyncCookie = Systrace.beginAsyncEvent(
@ -694,7 +694,7 @@ class CellRenderer extends React.Component<CellProps> {
this.props.onProgressChange({rowKey: this.props.rowKey, inProgress: false});
this.props.onWillUnmount(this.props.rowKey);
}
componentWillReceiveProps(newProps) {
UNSAFE_componentWillReceiveProps(newProps) {
if (newProps.includeInLayout && !this.props.includeInLayout) {
invariant(this._offscreenRenderDone, 'Should never try to add to layout before render done');
this._includeInLayoutLatch = true; // Once we render in layout, make sure it sticks.

View File

@ -92,7 +92,7 @@ class Inspector extends React.Component<{
hook.off('react-devtools', this.attachToDevtools);
}
componentWillReceiveProps(newProps: Object) {
UNSAFE_componentWillReceiveProps(newProps: Object) {
this.setState({inspectedViewTag: newProps.inspectedViewTag});
}

View File

@ -423,11 +423,11 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
}
}
componentWillMount() {
UNSAFE_componentWillMount() {
this._checkProps(this.props);
}
componentWillReceiveProps(nextProps: Props<ItemT>) {
UNSAFE_componentWillReceiveProps(nextProps: Props<ItemT>) {
invariant(
nextProps.numColumns === this.props.numColumns,
'Changing numColumns on the fly is not supported. Change the key prop on FlatList when ' +

View File

@ -354,7 +354,7 @@ var ListView = createReactClass({
return this._scrollComponent.getInnerViewNode();
},
componentWillMount: function() {
UNSAFE_componentWillMount: function() {
// this data should never trigger a render pass, so don't put in state
this.scrollProperties = {
visibleLength: null,
@ -375,7 +375,7 @@ var ListView = createReactClass({
});
},
componentWillReceiveProps: function(nextProps: Object) {
UNSAFE_componentWillReceiveProps: function(nextProps: Object) {
if (
this.props.dataSource !== nextProps.dataSource ||
this.props.initialListSize !== nextProps.initialListSize

View File

@ -135,7 +135,7 @@ class MetroListView extends React.Component<Props, $FlowFixMeState> {
}),
sectionHeaderData: {},
});
componentWillReceiveProps(newProps: Props) {
UNSAFE_componentWillReceiveProps(newProps: Props) {
this.setState(state => this._computeState(newProps, state));
}
render() {

View File

@ -611,7 +611,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
this._fillRateHelper.deactivateAndFlush();
}
componentWillReceiveProps(newProps: Props) {
UNSAFE_componentWillReceiveProps(newProps: Props) {
const {data, extraData, getItemCount, maxToRenderPerBatch} = newProps;
// first and last could be stale (e.g. if a new, shorter items props is passed in), so we make
// sure we're rendering a reasonable range here.

View File

@ -361,7 +361,7 @@ class VirtualizedSectionList<SectionT: SectionBase> extends React.PureComponent<
this.state = this._computeState(props);
}
componentWillReceiveProps(nextProps: Props<SectionT>) {
UNSAFE_componentWillReceiveProps(nextProps: Props<SectionT>) {
this.setState(this._computeState(nextProps));
}
@ -446,7 +446,7 @@ class ItemWithSeparator extends React.Component<
},
};
componentWillReceiveProps(props: ItemWithSeparatorProps) {
UNSAFE_componentWillReceiveProps(props: ItemWithSeparatorProps) {
this.setState(state => ({
separatorProps: {
...this.state.separatorProps,

View File

@ -151,7 +151,7 @@ class Modal extends React.Component<Object> {
}
}
componentWillReceiveProps(nextProps: Object) {
UNSAFE_componentWillReceiveProps(nextProps: Object) {
Modal._confirmProps(nextProps);
}

View File

@ -75,7 +75,7 @@ class AnExSet extends React.Component<Object, any> {
);
}
componentWillMount() {
UNSAFE_componentWillMount() {
this.state.dismissY = new Animated.Value(0);
this.state.dismissResponder = PanResponder.create({
onStartShouldSetPanResponder: () => this.props.isActive,

View File

@ -77,7 +77,7 @@ class AnExTilt extends React.Component<Object, any> {
}).start();
}
componentWillMount() {
UNSAFE_componentWillMount() {
this._startBurnsZoom();
}

View File

@ -126,7 +126,7 @@ var CameraRollView = createReactClass({
this.fetch();
},
componentWillReceiveProps: function(nextProps: {groupTypes?: string}) {
UNSAFE_componentWillReceiveProps: function(nextProps: {groupTypes?: string}) {
if (this.props.groupTypes !== nextProps.groupTypes) {
this.fetch(true);
}

View File

@ -43,7 +43,7 @@ var NetworkImageCallbackExample = createReactClass({
};
},
componentWillMount() {
UNSAFE_componentWillMount() {
this.setState({mountTime: new Date()});
},

View File

@ -26,7 +26,7 @@ class AddRemoveExample extends React.Component<{}, $FlowFixMeState> {
views: [],
};
componentWillUpdate() {
UNSAFE_componentWillUpdate() {
LayoutAnimation.easeInEaseOut();
}

View File

@ -41,7 +41,7 @@ var ListViewSimpleExample = createReactClass({
_pressData: ({}: {[key: number]: boolean}),
componentWillMount: function() {
UNSAFE_componentWillMount: function() {
this._pressData = {};
},

View File

@ -55,7 +55,7 @@ var ListViewGridLayoutExample = createReactClass({
_pressData: ({}: {[key: number]: boolean}),
componentWillMount: function() {
UNSAFE_componentWillMount: function() {
this._pressData = {};
},

View File

@ -46,7 +46,7 @@ var NUM_SECTIONS = 100;
var NUM_ROWS_PER_SECTION = 10;
class Thumb extends React.Component<{}, $FlowFixMeState> {
componentWillMount() {
UNSAFE_componentWillMount() {
UIManager.setLayoutAnimationEnabledExperimental &&
UIManager.setLayoutAnimationEnabledExperimental(true);
}

View File

@ -36,7 +36,7 @@ var PanResponderExample = createReactClass({
_circleStyles: {},
circle: (null : ?{ setNativeProps(props: Object): void }),
componentWillMount: function() {
UNSAFE_componentWillMount: function() {
this._panResponder = PanResponder.create({
onStartShouldSetPanResponder: this._handleStartShouldSetPanResponder,
onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder,

View File

@ -38,7 +38,7 @@ class Button extends React.Component<$FlowFixMeProps> {
}
class NotificationExample extends React.Component<{}> {
componentWillMount() {
UNSAFE_componentWillMount() {
PushNotificationIOS.addEventListener('register', this._onRegistered);
PushNotificationIOS.addEventListener('registrationError', this._onRegistrationError);
PushNotificationIOS.addEventListener('notification', this._onRemoteNotification);

View File

@ -57,7 +57,7 @@ const HEADER_NAV_ICON = nativeImageSource({
});
class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
componentWillMount() {
UNSAFE_componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', this._handleBackButtonPress);
}

View File

@ -57,7 +57,7 @@ const Header = ({ onBack, title }: { onBack?: () => mixed, title: string }) => (
);
class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
componentWillMount() {
UNSAFE_componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', this._handleBack);
}

View File

@ -19,7 +19,7 @@ const RNTesterStatePersister = require('./RNTesterStatePersister');
const View = require('View');
class RNTesterSettingSwitchRow extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
componentWillReceiveProps(newProps) {
UNSAFE_componentWillReceiveProps(newProps) {
const {onEnable, onDisable, persister} = this.props;
if (newProps.persister.state !== persister.state) {
newProps.persister.state ? onEnable() : onDisable();

View File

@ -42,7 +42,7 @@ var SwipeableListViewSimpleExample = createReactClass({
_pressData: ({}: {[key: number]: boolean}),
componentWillMount: function() {
UNSAFE_componentWillMount: function() {
this._pressData = {};
},

View File

@ -334,7 +334,7 @@ class AutogrowingTextInputExample extends React.Component<{}> {
};
}
componentWillReceiveProps(props) {
UNSAFE_componentWillReceiveProps(props) {
this.setState({
multiline: props.multiline,
});

View File

@ -352,7 +352,7 @@ class AutogrowingTextInputExample extends React.Component<$FlowFixMeProps, $Flow
};
}
componentWillReceiveProps(props) {
UNSAFE_componentWillReceiveProps(props) {
this.setState({
multiline: props.multiline,
});

View File

@ -22,7 +22,7 @@ class JSResponderTestApp extends React.Component {
return Math.abs(gestureState.dx) > 30;
};
componentWillMount() {
UNSAFE_componentWillMount() {
this.panGesture = PanResponder.create({
onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder,
});

View File

@ -28,7 +28,7 @@ class PickerAndroidTestApp extends React.Component {
style: {},
};
componentWillMount() {
UNSAFE_componentWillMount() {
appInstance = this;
}

View File

@ -267,7 +267,7 @@ var appInstance = null;
class SubviewsClippingTestApp extends React.Component {
state = {};
componentWillMount() {
UNSAFE_componentWillMount() {
appInstance = this;
}

View File

@ -1,3 +1,12 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
/* @flow */
@ -58,7 +67,7 @@ class KeyboardSpacerIOS extends Component<Props, State> {
keyboardHeight: 0,
};
componentWillMount() {
UNSAFE_componentWillMount() {
this._registerEvents();
}

View File

@ -143,7 +143,7 @@
"react-native": "local-cli/wrong-react-native.js"
},
"peerDependencies": {
"react": "16.2.0"
"react": "^16.3.0-alpha.0"
},
"dependencies": {
"absolute-path": "^0.0.0",
@ -219,8 +219,8 @@
"jest": "22.2.1",
"jest-junit": "3.5.0",
"prettier": "1.9.1",
"react": "16.2.0",
"react-test-renderer": "16.2.0",
"react": "^16.3.0-alpha.0",
"react-test-renderer": "^16.3.0-alpha.0",
"shelljs": "^0.7.8",
"sinon": "^2.2.0"
}