mirror of
https://github.com/status-im/react-native.git
synced 2025-02-22 22:28:09 +00:00
remove createReactClass from RNTester/js/ImageExample.js (#21602)
Summary: Related to #21581 . Removed createReactClass from the RNTester/js/ImageExample.js The diff of this PR is a little big. If there are any problems, please teach me � - [x] npm run prettier - [x] npm run flow-check-ios - [x] npm run flow-check-android [GENERAL] [ENHANCEMENT] [RNTester/js/ImageExample.js] - remove createReactClass dependency Pull Request resolved: https://github.com/facebook/react-native/pull/21602 Reviewed By: TheSavior Differential Revision: D10304857 Pulled By: RSNara fbshipit-source-id: 339b1220828c6218cad0d09c7a5034a61e623bc6
This commit is contained in:
parent
96bdfe3a60
commit
897f721728
@ -10,47 +10,62 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var React = require('react');
|
const React = require('react');
|
||||||
var createReactClass = require('create-react-class');
|
const ReactNative = require('react-native');
|
||||||
var ReactNative = require('react-native');
|
const {
|
||||||
var {
|
|
||||||
ActivityIndicator,
|
ActivityIndicator,
|
||||||
Image,
|
Image,
|
||||||
Platform,
|
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Text,
|
Text,
|
||||||
View,
|
View,
|
||||||
ImageBackground,
|
ImageBackground,
|
||||||
} = ReactNative;
|
} = ReactNative;
|
||||||
|
|
||||||
var base64Icon =
|
const base64Icon =
|
||||||
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAABLCAQAAACSR7JhAAADtUlEQVR4Ac3YA2Bj6QLH0XPT1Fzbtm29tW3btm3bfLZtv7e2ObZnms7d8Uw098tuetPzrxv8wiISrtVudrG2JXQZ4VOv+qUfmqCGGl1mqLhoA52oZlb0mrjsnhKpgeUNEs91Z0pd1kvihA3ULGVHiQO2narKSHKkEMulm9VgUyE60s1aWoMQUbpZOWE+kaqs4eLEjdIlZTcFZB0ndc1+lhB1lZrIuk5P2aib1NBpZaL+JaOGIt0ls47SKzLC7CqrlGF6RZ09HGoNy1lYl2aRSWL5GuzqWU1KafRdo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Yv1Qqsmh1s95S7G+eEWK0f3jYKTbV6bOwepjfhtafsvUsqrQvrGC8YhmnO9cSCk3yuY984F1vesdHYhWJ5FvASlacshUsajFt2mUM9pqzvKGcyNJW0arTKN1GGGzQlH0tXwLDgQTurS8eIQAAAABJRU5ErkJggg==';
|
||||||
|
|
||||||
var ImageCapInsetsExample = require('./ImageCapInsetsExample');
|
const ImageCapInsetsExample = require('./ImageCapInsetsExample');
|
||||||
const IMAGE_PREFETCH_URL =
|
const IMAGE_PREFETCH_URL =
|
||||||
'http://origami.design/public/images/bird-logo.png?r=1&t=' + Date.now();
|
'http://origami.design/public/images/bird-logo.png?r=1&t=' + Date.now();
|
||||||
var prefetchTask = Image.prefetch(IMAGE_PREFETCH_URL);
|
const prefetchTask = Image.prefetch(IMAGE_PREFETCH_URL);
|
||||||
|
|
||||||
/* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an error
|
type ImageSource = $ReadOnly<{|
|
||||||
* found when Flow v0.63 was deployed. To see the error delete this comment and
|
uri: string,
|
||||||
* run Flow. */
|
|}>;
|
||||||
var NetworkImageCallbackExample = createReactClass({
|
|
||||||
displayName: 'NetworkImageCallbackExample',
|
type NetworkImageCallbackExampleState = {|
|
||||||
getInitialState: function() {
|
events: Array<string>,
|
||||||
return {
|
startLoadPrefetched: boolean,
|
||||||
events: [],
|
mountTime: Date,
|
||||||
startLoadPrefetched: false,
|
|};
|
||||||
mountTime: new Date(),
|
|
||||||
};
|
type NetworkImageCallbackExampleProps = $ReadOnly<{|
|
||||||
},
|
source: ImageSource,
|
||||||
|
prefetchedSource: ImageSource,
|
||||||
|
|}>;
|
||||||
|
|
||||||
|
class NetworkImageCallbackExample extends React.Component<
|
||||||
|
NetworkImageCallbackExampleProps,
|
||||||
|
NetworkImageCallbackExampleState,
|
||||||
|
> {
|
||||||
|
state = {
|
||||||
|
events: [],
|
||||||
|
startLoadPrefetched: false,
|
||||||
|
mountTime: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
UNSAFE_componentWillMount() {
|
UNSAFE_componentWillMount() {
|
||||||
this.setState({mountTime: new Date()});
|
this.setState({mountTime: new Date()});
|
||||||
},
|
}
|
||||||
|
|
||||||
render: function() {
|
_loadEventFired = (event: string) => {
|
||||||
var {mountTime} = this.state;
|
this.setState(state => ({
|
||||||
|
events: [...state.events, event],
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {mountTime} = this.state;
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<Image
|
<Image
|
||||||
@ -133,24 +148,30 @@ var NetworkImageCallbackExample = createReactClass({
|
|||||||
<Text style={{marginTop: 20}}>{this.state.events.join('\n')}</Text>
|
<Text style={{marginTop: 20}}>{this.state.events.join('\n')}</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_loadEventFired(event) {
|
type NetworkImageExampleState = {|
|
||||||
this.setState(state => {
|
error: boolean,
|
||||||
return (state.events = [...state.events, event]);
|
loading: boolean,
|
||||||
});
|
progress: number,
|
||||||
},
|
|};
|
||||||
});
|
|
||||||
|
|
||||||
var NetworkImageExample = createReactClass({
|
type NetworkImageExampleProps = $ReadOnly<{|
|
||||||
getInitialState: function() {
|
source: ImageSource,
|
||||||
return {
|
|}>;
|
||||||
error: false,
|
|
||||||
loading: false,
|
class NetworkImageExample extends React.Component<
|
||||||
progress: 0,
|
NetworkImageExampleProps,
|
||||||
};
|
NetworkImageExampleState,
|
||||||
},
|
> {
|
||||||
render: function() {
|
state = {
|
||||||
|
error: false,
|
||||||
|
loading: false,
|
||||||
|
progress: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
var loader = this.state.loading ? (
|
var loader = this.state.loading ? (
|
||||||
<View style={styles.progress}>
|
<View style={styles.progress}>
|
||||||
<Text>{this.state.progress}%</Text>
|
<Text>{this.state.progress}%</Text>
|
||||||
@ -178,22 +199,34 @@ var NetworkImageExample = createReactClass({
|
|||||||
{loader}
|
{loader}
|
||||||
</ImageBackground>
|
</ImageBackground>
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
var ImageSizeExample = createReactClass({
|
type ImageSizeExampleState = {|
|
||||||
getInitialState: function() {
|
width: number,
|
||||||
return {
|
height: number,
|
||||||
width: 0,
|
|};
|
||||||
height: 0,
|
|
||||||
};
|
type ImageSizeExampleProps = $ReadOnly<{|
|
||||||
},
|
source: ImageSource,
|
||||||
componentDidMount: function() {
|
|}>;
|
||||||
|
|
||||||
|
class ImageSizeExample extends React.Component<
|
||||||
|
ImageSizeExampleProps,
|
||||||
|
ImageSizeExampleState,
|
||||||
|
> {
|
||||||
|
state = {
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
Image.getSize(this.props.source.uri, (width, height) => {
|
Image.getSize(this.props.source.uri, (width, height) => {
|
||||||
this.setState({width, height});
|
this.setState({width, height});
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
render: function() {
|
|
||||||
|
render() {
|
||||||
return (
|
return (
|
||||||
<View style={{flexDirection: 'row'}}>
|
<View style={{flexDirection: 'row'}}>
|
||||||
<Image
|
<Image
|
||||||
@ -211,17 +244,56 @@ var ImageSizeExample = createReactClass({
|
|||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
var MultipleSourcesExample = createReactClass({
|
type MultipleSourcesExampleState = {|
|
||||||
getInitialState: function() {
|
width: number,
|
||||||
return {
|
height: number,
|
||||||
width: 30,
|
|};
|
||||||
height: 30,
|
|
||||||
};
|
type MultipleSourcesExampleProps = $ReadOnly<{||}>;
|
||||||
},
|
|
||||||
render: function() {
|
class MultipleSourcesExample extends React.Component<
|
||||||
|
MultipleSourcesExampleProps,
|
||||||
|
MultipleSourcesExampleState,
|
||||||
|
> {
|
||||||
|
state = {
|
||||||
|
width: 30,
|
||||||
|
height: 30,
|
||||||
|
};
|
||||||
|
|
||||||
|
increaseImageSize = () => {
|
||||||
|
if (this.state.width >= 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
width: this.state.width + 10,
|
||||||
|
height: this.state.height + 10,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
increaseImageSize = () => {
|
||||||
|
if (this.state.width >= 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
width: this.state.width + 10,
|
||||||
|
height: this.state.height + 10,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
decreaseImageSize = () => {
|
||||||
|
if (this.state.width <= 10) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
width: this.state.width - 10,
|
||||||
|
height: this.state.height - 10,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
|
<View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
|
||||||
@ -260,26 +332,8 @@ var MultipleSourcesExample = createReactClass({
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
increaseImageSize: function() {
|
}
|
||||||
if (this.state.width >= 100) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.setState({
|
|
||||||
width: this.state.width + 10,
|
|
||||||
height: this.state.height + 10,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
decreaseImageSize: function() {
|
|
||||||
if (this.state.width <= 10) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.setState({
|
|
||||||
width: this.state.width - 10,
|
|
||||||
height: this.state.height - 10,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
exports.displayName = (undefined: ?string);
|
exports.displayName = (undefined: ?string);
|
||||||
exports.framework = 'React';
|
exports.framework = 'React';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user