Skip to content
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

[createReactClass] remove createReactClass from the IntegrationTests/ReactContentSizeUpdateTest.js #21622

Closed
Closed
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
64 changes: 33 additions & 31 deletions IntegrationTests/ReactContentSizeUpdateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'use strict';

const React = require('react');
const createReactClass = require('create-react-class');
const ReactNative = require('react-native');
const RCTNativeAppEventEmitter = require('RCTNativeAppEventEmitter');

Expand All @@ -25,64 +24,67 @@ const reactViewHeight = 102;
const newReactViewWidth = 201;
const newReactViewHeight = 202;

const ReactContentSizeUpdateTest = createReactClass({
displayName: 'ReactContentSizeUpdateTest',
_timeoutID: (null: ?TimeoutID),
_subscription: (null: ?EmitterSubscription),
type State = {|
height: number,
width: number,
|};

UNSAFE_componentWillMount: function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier/prettier: Insert ·

class ReactContentSizeUpdateTest extends React.Component<{}, State> {
_timeoutID: ?TimeoutID = null;
_subscription: ?EmitterSubscription = null;

state = {
height: reactViewHeight,
width: reactViewWidth,
};

UNSAFE_componentWillMount() {
this._subscription = RCTNativeAppEventEmitter.addListener(
'rootViewDidChangeIntrinsicSize',
this.rootViewDidChangeIntrinsicSize,
);
},

getInitialState: function() {
return {
height: reactViewHeight,
width: reactViewWidth,
};
},

updateViewSize: function() {
this.setState({
height: newReactViewHeight,
width: newReactViewWidth,
});
},
}

componentDidMount: function() {
componentDidMount() {
this._timeoutID = setTimeout(() => {
this.updateViewSize();
}, 1000);
},
}

componentWillUnmount: function() {
componentWillUnmount() {
if (this._timeoutID != null) {
clearTimeout(this._timeoutID);
}

if (this._subscription != null) {
this._subscription.remove();
}
},
}

rootViewDidChangeIntrinsicSize: function(intrinsicSize) {
updateViewSize = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only call-site for this method is in componentDidMount:

componentDidMount() {
    this._timeoutID = setTimeout(() => {
      this.updateViewSize();
    }, 1000);
  },

Given the way it's called, we don't need to bind this function.

this.setState({
height: newReactViewHeight,
width: newReactViewWidth,
});
};

rootViewDidChangeIntrinsicSize = (intrinsicSize: {
height: number,
width: number,
}) => {
if (
intrinsicSize.height === newReactViewHeight &&
intrinsicSize.width === newReactViewWidth
) {
TestModule.markTestPassed(true);
}
},
};

render() {
return (
<View style={{height: this.state.height, width: this.state.width}} />
);
},
});

ReactContentSizeUpdateTest.displayName = 'ReactContentSizeUpdateTest';
}
}

module.exports = ReactContentSizeUpdateTest;