-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
85 lines (75 loc) · 1.8 KB
/
App.js
File metadata and controls
85 lines (75 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React from 'react';
import { StyleSheet, Text, View, TextInput } from 'react-native';
import { sort } from './bubble_sort.js';
class AnswerNumber extends React.Component {
render() {
return <Text>{this.props.item}</Text>;
}
}
class Answer extends React.Component {
render() {
return <View>
<Text style={{ width: 200 }}>Answer:</Text>
{this.props.items.map((item, index) => <AnswerNumber key={index} item={item} />)}
</View>;
}
}
class Input extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.state = {
value: this.props.value
};
}
handleChange(changedText) {
this.setState({
value: changedText,
})
if (this.props.onChange) {
this.props.onChange(changedText);
}
}
render() {
return <View>
<Text>Input:</Text>
<TextInput
style={{ height: 40, borderColor: 'gray', borderWidth: 1, width: 200 }}
onChangeText={this.handleChange}
value={this.state.value}
/>
</View>;
}
}
export default class App extends React.Component {
constructor(props) {
super(props);
this.answer = [];
this.changeInput = this.changeInput.bind(this);
this.state = {
input: "4 3 2 1",
answer: ["1", "2", "3", "4"],
};
}
changeInput(inputStr) {
const list = inputStr.split(" ").map(n => parseInt(n, 10));
sort(list);
this.setState({
input: inputStr,
answer: list,
});
}
render() {
return (
<View style={{
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
}} >
<Input onChange={this.changeInput} value={this.state.input} />
<Answer items={this.state.answer} />
</View>
);
}
}