From fb719e2d6ca505eda5a2f9a55870fb3eec6ea1fb Mon Sep 17 00:00:00 2001 From: Thomas BARRAS Date: Fri, 2 Nov 2018 12:10:49 -0700 Subject: [PATCH] Remove createReactClass from ProgressBarAndroidExample (#21874) Summary: Related to #21581 This PR was already opened here https://github.com/facebook/react-native/pull/21600 but seems to be inactive. Remove createReactClass from ProgressBarAndroidExample. - `yarn run flow` && `yarn run flow-check-android` succeed. - RNTester app ProgressBarAndroidExample on Android. [GENERAL] [ENHANCEMENT] [ProgressBarAndroidExample.android.js] - rm createReactClass Pull Request resolved: https://github.com/facebook/react-native/pull/21874 Reviewed By: TheSavior Differential Revision: D12827689 Pulled By: RSNara fbshipit-source-id: 46c70ea67dddf5d928fe936a28ef4a0a929d127f --- js/ProgressBarAndroidExample.android.js | 46 ++++++++++++++++--------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/js/ProgressBarAndroidExample.android.js b/js/ProgressBarAndroidExample.android.js index c806a4c6c33..9c45fc54c40 100644 --- a/js/ProgressBarAndroidExample.android.js +++ b/js/ProgressBarAndroidExample.android.js @@ -12,37 +12,49 @@ const ProgressBar = require('ProgressBarAndroid'); const React = require('React'); -const createReactClass = require('create-react-class'); const RNTesterBlock = require('RNTesterBlock'); const RNTesterPage = require('RNTesterPage'); -const MovingBar = createReactClass({ - displayName: 'MovingBar', - _intervalID: (null: ?IntervalID), +import type {ProgressBarAndroidProps} from 'ProgressBarAndroid'; - getInitialState: function() { - return { - progress: 0, - }; - }, +type MovingBarProps = $ReadOnly<{| + ...$Diff< + ProgressBarAndroidProps, + { + progress: ?number, + }, + >, + indeterminate: false, +|}>; - componentDidMount: function() { +type MovingBarState = { + progress: number, +}; + +class MovingBar extends React.Component { + _intervalID: ?IntervalID = null; + + state = { + progress: 0, + }; + + componentDidMount() { this._intervalID = setInterval(() => { const progress = (this.state.progress + 0.02) % 1; - this.setState({progress: progress}); + this.setState({progress}); }, 50); - }, + } - componentWillUnmount: function() { + componentWillUnmount() { if (this._intervalID != null) { clearInterval(this._intervalID); } - }, + } - render: function() { + render() { return ; - }, -}); + } +} class ProgressBarAndroidExample extends React.Component<{}> { static title = '';