Skip to content

Commit afb805a

Browse files
author
alvaromb
committed
Solved antipattern issue
Reverted part of #483 due to arising bugs when locals change. Migrated from controlled-uncontrolled antipattern
1 parent 460f7ef commit afb805a

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

lib/templates/bootstrap/select.ios.js

+15-20
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,12 @@ class CollapsiblePickerIOS extends React.Component {
1616
isCollapsed,
1717
height: new Animated.Value(isCollapsed ? 0 : UIPICKER_HEIGHT)
1818
};
19-
this.animatePicker = this.animatePicker.bind(this);
20-
this.togglePicker = this.togglePicker.bind(this);
19+
this.animatePicker = this._animatePicker.bind(this);
20+
this.togglePicker = this._togglePicker.bind(this);
21+
this.onValueChange = this._onValueChange.bind(this);
2122
}
2223

23-
componentWillReceiveProps(props) {
24-
const isCollapsed =
25-
typeof props.locals.isCollapsed === typeof true
26-
? props.locals.isCollapsed
27-
: this.props.locals.isCollapsed;
28-
if (isCollapsed !== this.state.isCollapsed) {
29-
this.animatePicker(isCollapsed);
30-
this.setState({ isCollapsed });
31-
if (typeof props.locals.onCollapseChange === "function") {
32-
props.locals.onCollapseChange(isCollapsed);
33-
}
34-
}
35-
}
36-
37-
animatePicker(isCollapsed) {
24+
_animatePicker(isCollapsed) {
3825
const locals = this.props.locals;
3926
let animation = Animated.timing;
4027
let animationConfig = {
@@ -48,7 +35,6 @@ class CollapsiblePickerIOS extends React.Component {
4835
animationConfig = locals.config.animationConfig;
4936
}
5037
}
51-
5238
animation(
5339
this.state.height,
5440
Object.assign(
@@ -60,7 +46,7 @@ class CollapsiblePickerIOS extends React.Component {
6046
).start();
6147
}
6248

63-
togglePicker() {
49+
_togglePicker() {
6450
this.setState({ isCollapsed: !this.state.isCollapsed }, () => {
6551
this.animatePicker(this.state.isCollapsed);
6652
if (typeof this.props.locals.onCollapseChange === "function") {
@@ -69,6 +55,14 @@ class CollapsiblePickerIOS extends React.Component {
6955
});
7056
}
7157

58+
_onValueChange(val) {
59+
const { onChange, value } = this.props.locals;
60+
if (val !== value) {
61+
this.togglePicker();
62+
onChange(val);
63+
}
64+
}
65+
7266
render() {
7367
const locals = this.props.locals;
7468
const { stylesheet } = locals;
@@ -97,6 +91,7 @@ class CollapsiblePickerIOS extends React.Component {
9791
);
9892

9993
const height = this.state.isCollapsed ? 0 : UIPICKER_HEIGHT;
94+
10095
return (
10196
<View
10297
style={[
@@ -122,7 +117,7 @@ class CollapsiblePickerIOS extends React.Component {
122117
ref="input"
123118
style={selectStyle}
124119
selectedValue={locals.value}
125-
onValueChange={locals.onChange}
120+
onValueChange={this.onValueChange}
126121
help={locals.help}
127122
enabled={!locals.disabled}
128123
mode={locals.mode}

0 commit comments

Comments
 (0)