2015-11-19 21:32:37 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-11-19 21:32:37 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-05-10 22:44:55 +00:00
|
|
|
*
|
|
|
|
* @format
|
2018-10-08 21:52:08 +00:00
|
|
|
* @flow
|
2015-11-19 21:32:37 +00:00
|
|
|
*/
|
2018-05-10 22:44:55 +00:00
|
|
|
|
2015-11-19 21:32:37 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-14 07:09:36 +00:00
|
|
|
const React = require('react');
|
|
|
|
const ReactNative = require('react-native');
|
|
|
|
const RCTNativeAppEventEmitter = require('RCTNativeAppEventEmitter');
|
2015-11-19 21:32:37 +00:00
|
|
|
|
2018-05-14 07:09:36 +00:00
|
|
|
const {View} = ReactNative;
|
2015-11-19 21:32:37 +00:00
|
|
|
|
2018-05-14 07:09:36 +00:00
|
|
|
const {TestModule} = ReactNative.NativeModules;
|
2018-10-08 21:52:08 +00:00
|
|
|
import type EmitterSubscription from 'EmitterSubscription';
|
2015-11-19 21:32:37 +00:00
|
|
|
|
2018-05-14 07:09:36 +00:00
|
|
|
const reactViewWidth = 101;
|
|
|
|
const reactViewHeight = 102;
|
|
|
|
const newReactViewWidth = 201;
|
|
|
|
const newReactViewHeight = 202;
|
2015-11-19 21:32:37 +00:00
|
|
|
|
2018-10-10 21:34:00 +00:00
|
|
|
type Props = {||};
|
2015-11-19 21:32:37 +00:00
|
|
|
|
2018-10-10 21:34:00 +00:00
|
|
|
type State = {|
|
|
|
|
height: number,
|
|
|
|
width: number,
|
|
|
|
|};
|
|
|
|
|
|
|
|
class ReactContentSizeUpdateTest extends React.Component<Props, State> {
|
|
|
|
_timeoutID: ?TimeoutID = null;
|
|
|
|
_subscription: ?EmitterSubscription = null;
|
|
|
|
|
|
|
|
state = {
|
|
|
|
height: reactViewHeight,
|
|
|
|
width: reactViewWidth,
|
|
|
|
};
|
|
|
|
|
|
|
|
UNSAFE_componentWillMount() {
|
2018-10-08 21:52:08 +00:00
|
|
|
this._subscription = RCTNativeAppEventEmitter.addListener(
|
2015-11-19 21:32:37 +00:00
|
|
|
'rootViewDidChangeIntrinsicSize',
|
2018-05-10 22:44:55 +00:00
|
|
|
this.rootViewDidChangeIntrinsicSize,
|
2015-11-19 21:32:37 +00:00
|
|
|
);
|
2018-10-10 21:34:00 +00:00
|
|
|
}
|
2015-11-19 21:32:37 +00:00
|
|
|
|
2018-10-10 21:34:00 +00:00
|
|
|
componentDidMount() {
|
2018-10-05 20:52:43 +00:00
|
|
|
this._timeoutID = setTimeout(() => {
|
2018-05-10 22:44:55 +00:00
|
|
|
this.updateViewSize();
|
|
|
|
}, 1000);
|
2018-10-10 21:34:00 +00:00
|
|
|
}
|
2015-11-19 21:32:37 +00:00
|
|
|
|
2018-10-10 21:34:00 +00:00
|
|
|
componentWillUnmount() {
|
2018-10-05 20:52:43 +00:00
|
|
|
if (this._timeoutID != null) {
|
|
|
|
clearTimeout(this._timeoutID);
|
|
|
|
}
|
2018-10-08 21:52:08 +00:00
|
|
|
|
|
|
|
if (this._subscription != null) {
|
|
|
|
this._subscription.remove();
|
|
|
|
}
|
2018-10-10 21:34:00 +00:00
|
|
|
}
|
2018-10-05 20:52:43 +00:00
|
|
|
|
2018-10-10 21:34:00 +00:00
|
|
|
updateViewSize() {
|
|
|
|
this.setState({
|
|
|
|
height: newReactViewHeight,
|
|
|
|
width: newReactViewWidth,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
rootViewDidChangeIntrinsicSize = (intrinsicSize: State) => {
|
2018-05-10 22:44:55 +00:00
|
|
|
if (
|
|
|
|
intrinsicSize.height === newReactViewHeight &&
|
|
|
|
intrinsicSize.width === newReactViewWidth
|
|
|
|
) {
|
2015-11-19 21:32:37 +00:00
|
|
|
TestModule.markTestPassed(true);
|
|
|
|
}
|
2018-10-10 21:34:00 +00:00
|
|
|
};
|
2015-11-19 21:32:37 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2018-05-10 22:44:55 +00:00
|
|
|
<View style={{height: this.state.height, width: this.state.width}} />
|
2015-11-19 21:32:37 +00:00
|
|
|
);
|
2018-10-10 21:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-19 21:32:37 +00:00
|
|
|
|
|
|
|
module.exports = ReactContentSizeUpdateTest;
|