Skip to content

Use new/temporary react lifecycle methods (#1039) #1127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/navigation/src/web/Navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class NavigatorImpl extends NavigatorBase<NavigatorState> {
};
}

componentWillMount() {
UNSAFE_componentWillMount() {
this.springSystem = new rebound.SpringSystem();
this.spring = this.springSystem.createSpring();
this.spring.setRestSpeedThreshold(0.05);
Expand Down
2 changes: 1 addition & 1 deletion extensions/virtuallistview/src/VirtualListCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class VirtualListCell<ItemInfo extends VirtualListCellInfo> extends RX.Co
});
}

componentWillReceiveProps(nextProps: VirtualListCellProps<ItemInfo>) {
UNSAFE_componentWillReceiveProps(nextProps: VirtualListCellProps<ItemInfo>) {
// If it's inactive, it had better be invisible.
assert(nextProps.isActive || !nextProps.isVisible);

Expand Down
4 changes: 2 additions & 2 deletions extensions/virtuallistview/src/VirtualListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ export class VirtualListView<ItemInfo extends VirtualListViewItemInfo>
};
}

componentWillReceiveProps(nextProps: VirtualListViewProps<ItemInfo>): void {
UNSAFE_componentWillReceiveProps(nextProps: VirtualListViewProps<ItemInfo>): void {
if (!_.isEqual(this.props, nextProps)) {
this._updateStateFromProps(nextProps, false);
}
}

componentWillUpdate(nextProps: VirtualListViewProps<ItemInfo>, nextState: VirtualListViewState) {
UNSAFE_componentWillUpdate(nextProps: VirtualListViewProps<ItemInfo>, nextState: VirtualListViewState) {
const updatedState: Partial<VirtualListViewState> = {};
let updateState = false;
if (nextState.lastFocusedItemKey && !_.some(nextProps.itemList, item => item.key === nextState.lastFocusedItemKey)) {
Expand Down
1 change: 1 addition & 0 deletions samples/RXPTest/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class App extends RX.Component<RX.CommonProps, AppState> {

// If there are more tests to run, move on to the next one.
if (curTestIndex + 1 < testPaths.length) {
console.log('state selectedTest moving to: ', testPaths[curTestIndex + 1]);
this.setState({ selectedTest: testPaths[curTestIndex + 1] });
return;
}
Expand Down
2 changes: 1 addition & 1 deletion samples/RXPTest/src/Tests/AlertTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const _styles = {
color: 'black'
}),
buttonPanel: RX.Styles.createViewStyle({
flexDirection: 'row'
flexDirection: 'column'
}),
alertBody: RX.Styles.createViewStyle({
backgroundColor: '#333',
Expand Down
8 changes: 6 additions & 2 deletions samples/RXPTest/src/Tests/ViewMouseTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,19 @@ class MouseView extends RX.Component<RX.CommonProps, MouseViewState> {
{ 'blockPointerEvents:' + (this.state.blockPointerEvents ? 'true' : 'false') }
</RX.Text>
<RX.Button onPress={this.toggleBlockPointerEvents}>
{ this.state.blockPointerEvents ? 'Enable' : 'Disable' }
<RX.Text style={ _styles.labelText }>
{ this.state.blockPointerEvents ? 'Enable' : 'Disable' }
</RX.Text>
</RX.Button>
</RX.View>
<RX.View style={_styles.row}>
<RX.Text style={ _styles.labelText }>
ignorePointerEvents: {this.state.ignorePointerEvents ? 'true' : 'false' }
</RX.Text>
<RX.Button onPress={this.toggleIgnorePointerEvents}>
{ this.state.ignorePointerEvents ? 'Enable' : 'Disable' }
<RX.Text style={ _styles.labelText }>
{ this.state.ignorePointerEvents ? 'Enable' : 'Disable' }
</RX.Text>
</RX.Button>
</RX.View>
</RX.View>
Expand Down
8 changes: 4 additions & 4 deletions samples/TodoList/src/ts/controls/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ export default class Modal extends ComponentBase<ModalProps, ModalState> {
return newState;
}

componentWillMount() {
UNSAFE_componentWillMount() {
// To give children a chance to cancel the ESC handler,
// subscribing in componentWillMount so that the children
// could subscribe after.
super.componentWillMount();
super.UNSAFE_componentWillMount();

RX.Input.keyUpEvent.subscribe(this._onKeyUp);
}
Expand All @@ -113,8 +113,8 @@ export default class Modal extends ComponentBase<ModalProps, ModalState> {
RX.Input.keyUpEvent.unsubscribe(this._onKeyUp);
}

componentWillUpdate(newProps: ModalProps, newState: ModalState, newContext: any) {
super.componentWillUpdate(newProps, newState, newContext);
UNSAFE_componentWillUpdate(newProps: ModalProps, newState: ModalState, newContext: any) {
super.UNSAFE_componentWillUpdate(newProps, newState, newContext);

// We assume the modalId doesn't change.
assert.ok(newProps.modalId === this.props.modalId);
Expand Down
2 changes: 1 addition & 1 deletion src/native-common/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class Button extends ButtonBase {
this._isMounted = false;
}

componentWillReceiveProps(nextProps: Types.ButtonProps) {
UNSAFE_componentWillReceiveProps(nextProps: Types.ButtonProps) {
// If opacity styles were updated as a part of props update, we need to reflect that in the opacity animation value
this._setOpacityStyles(nextProps, this.props);
}
Expand Down
2 changes: 1 addition & 1 deletion src/native-common/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class Image extends React.Component<Types.ImageProps, ImageState> impleme
);
}

componentWillReceiveProps(nextProps: Types.ImageProps) {
UNSAFE_componentWillReceiveProps(nextProps: Types.ImageProps) {
const sourceOrHeaderChanged = (nextProps.source !== this.props.source ||
!_.isEqual(nextProps.headers || {}, this.props.headers || {}));
if (sourceOrHeaderChanged) {
Expand Down
2 changes: 1 addition & 1 deletion src/native-common/PopupContainerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class PopupContainerView extends PopupContainerViewBase<PopupContainerVie
};
}

componentWillReceiveProps(prevProps: PopupContainerViewProps) {
UNSAFE_componentWillReceiveProps(prevProps: PopupContainerViewProps) {
if (this.props.popupOptions !== prevProps.popupOptions) {
// If the popup changes, reset our state.
this.setState(this._getInitialState());
Expand Down
6 changes: 3 additions & 3 deletions src/native-common/RootView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class BaseRootView<P extends BaseRootViewProps> extends React.Component
this._mainViewProps = this._getPropsForMainView();
}

componentWillMount(): void {
UNSAFE_componentWillMount(): void {
this._frontLayerViewChangedSubscription = FrontLayerViewManager.event_changed.subscribe(() => {
// Setting empty state will trigger a render.
this.setState({});
Expand Down Expand Up @@ -175,8 +175,8 @@ class RootViewUsingStore extends BaseRootView<BaseRootViewProps> {
};
}

componentWillMount(): void {
super.componentWillMount();
UNSAFE_componentWillMount(): void {
super.UNSAFE_componentWillMount();

MainViewStore.subscribe(this._changeListener);
this.setState(this._getStateFromStore());
Expand Down
2 changes: 1 addition & 1 deletion src/native-common/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class TextInput extends React.Component<Types.TextInputProps, TextInputSt
};
}

componentWillReceiveProps(nextProps: Types.TextInputProps) {
UNSAFE_componentWillReceiveProps(nextProps: Types.TextInputProps) {
if (nextProps.value !== undefined && nextProps.value !== this.state.inputValue) {
this.setState({
inputValue: nextProps.value || ''
Expand Down
4 changes: 2 additions & 2 deletions src/native-common/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class View extends ViewBase<RX.Types.ViewProps, RX.Types.Stateless, RN.Vi
}
}

componentWillReceiveProps(nextProps: RX.Types.ViewProps) {
UNSAFE_componentWillReceiveProps(nextProps: RX.Types.ViewProps) {
this._updateMixin(nextProps, false);
this._buildInternalProps(nextProps);

Expand All @@ -184,7 +184,7 @@ export class View extends ViewBase<RX.Types.ViewProps, RX.Types.Stateless, RN.Vi
}
}

componentWillUpdate(nextProps: RX.Types.ViewProps, nextState: {}) {
UNSAFE_componentWillUpdate(nextProps: RX.Types.ViewProps, nextState: {}) {
//
// Exit fast if not an "animated children" case
if (!(nextProps.animateChildEnter || nextProps.animateChildMove || nextProps.animateChildLeave)) {
Expand Down
2 changes: 1 addition & 1 deletion src/web/Animated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ function createAnimatedComponent<PropsType extends RX.Types.CommonProps<C>, C>(C
}
}

componentWillReceiveProps(props: RX.Types.CommonStyledProps<RX.Types.StyleRuleSet<Object>, C>) {
UNSAFE_componentWillReceiveProps(props: RX.Types.CommonStyledProps<RX.Types.StyleRuleSet<Object>, C>) {
this._updateStyles(props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/web/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class Image extends React.Component<Types.ImageProps, ImageState> {
}
}

componentWillReceiveProps(nextProps: Types.ImageProps) {
UNSAFE_componentWillReceiveProps(nextProps: Types.ImageProps) {
const sourceOrHeaderChanged = (nextProps.source !== this.props.source ||
!_.isEqual(nextProps.headers || {}, this.props.headers || {}));

Expand Down
2 changes: 1 addition & 1 deletion src/web/RootView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class RootView extends React.Component<RootViewProps, RootViewState> {
};
}

componentWillReceiveProps(prevProps: RootViewProps) {
UNSAFE_componentWillReceiveProps(prevProps: RootViewProps) {
if (this.props.activePopup !== prevProps.activePopup) {
this._stopHidePopupTimer();

Expand Down
6 changes: 3 additions & 3 deletions src/web/ScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class ScrollView extends ViewBase<RX.Types.ScrollViewProps, RX.Types.Stat
return this._customScrollbarEnabled ? this._renderWithCustomScrollbar() : this._renderNormal();
}

componentWillMount() {
UNSAFE_componentWillMount() {
this._onPropsChange(this.props);
}

Expand All @@ -155,8 +155,8 @@ export class ScrollView extends ViewBase<RX.Types.ScrollViewProps, RX.Types.Stat
this._createCustomScrollbarsIfNeeded(this.props);
}

componentWillReceiveProps(newProps: RX.Types.ScrollViewProps) {
super.componentWillReceiveProps(newProps);
UNSAFE_componentWillReceiveProps(newProps: RX.Types.ScrollViewProps) {
super.UNSAFE_componentWillReceiveProps(newProps);
this._onPropsChange(newProps);
}

Expand Down
2 changes: 1 addition & 1 deletion src/web/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class TextInput extends React.Component<Types.TextInputProps, TextInputSt
};
}

componentWillReceiveProps(nextProps: Types.TextInputProps) {
UNSAFE_componentWillReceiveProps(nextProps: Types.TextInputProps) {
const nextState: Partial<TextInputState> = {};

if (nextProps.value !== undefined && nextProps.value !== this.state.inputValue) {
Expand Down
4 changes: 2 additions & 2 deletions src/web/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ export class View extends ViewBase<RX.Types.ViewProps, RX.Types.Stateless, RX.Vi
reactElement;
}

componentWillReceiveProps(nextProps: RX.Types.ViewProps) {
super.componentWillReceiveProps(nextProps);
UNSAFE_componentWillReceiveProps(nextProps: RX.Types.ViewProps) {
super.UNSAFE_componentWillReceiveProps(nextProps);

if (AppConfig.isDevelopmentMode()) {
if (this.props.restrictFocusWithin !== nextProps.restrictFocusWithin) {
Expand Down
2 changes: 1 addition & 1 deletion src/web/ViewBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export abstract class ViewBase<P extends RX.Types.ViewPropsShared<C>, S, C exten
}
}

componentWillReceiveProps(nextProps: RX.Types.ViewPropsShared<C>) {
UNSAFE_componentWillReceiveProps(nextProps: RX.Types.ViewPropsShared<C>) {
if (!!this.props.onLayout !== !!nextProps.onLayout) {
if (this.props.onLayout) {
this._checkViewCheckerUnbuild();
Expand Down
4 changes: 2 additions & 2 deletions src/web/listAnimations/MonitorListEdits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class MonitorListEdits extends React.Component<MonitorListEditsProps, Typ
private _phase: ComponentPhaseEnum = ComponentPhaseEnum.rest;
private _willAnimatePhaseInfo: WillAnimatePhaseInfo | undefined;

componentWillMount() {
UNSAFE_componentWillMount() {
this._childrenKeys = extractChildrenKeys(this.props.children);
this._childrenMap = createChildrenMap(this.props.children);
}
Expand All @@ -174,7 +174,7 @@ export class MonitorListEdits extends React.Component<MonitorListEditsProps, Typ
return this._phase !== ComponentPhaseEnum.animating;
}

componentWillUpdate(nextProps: MonitorListEditsProps) {
UNSAFE_componentWillUpdate(nextProps: MonitorListEditsProps) {
assert(
this._phase !== ComponentPhaseEnum.animating,
'componentWillUpdate should never run while the component is animating due to the implementation of shouldComponentUpdate'
Expand Down
4 changes: 2 additions & 2 deletions src/windows/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ export class View extends ViewCommon implements React.ChildContextProvider<ViewC
this._popupContainer = context && context.popupContainer;
}

componentWillReceiveProps(nextProps: Types.ViewProps) {
super.componentWillReceiveProps(nextProps);
UNSAFE_componentWillReceiveProps(nextProps: Types.ViewProps) {
super.UNSAFE_componentWillReceiveProps(nextProps);

if (AppConfig.isDevelopmentMode()) {
if (this.props.restrictFocusWithin !== nextProps.restrictFocusWithin) {
Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"rules": {
// Rules from tslint-microsoft-contrib
"function-name": [true, {
"method-regex": "^[a-z]\\w+$",
"method-regex": "^(UNSAFE_)?[a-z]\\w+$",
"private-method-regex": "^_[a-z]\\w+$",
"protected-method-regex": "^[a-z_]\\w+$",
"static-method-regex": "^[a-z]\\w+$",
Expand Down