Skip to content

Commit 0861d0a

Browse files
committed
Add adjustFrame API
1 parent 0fa583c commit 0861d0a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

components/ModalDropdown.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default class ModalDropdown extends Component {
4444
textStyle: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
4545
dropdownStyle: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
4646

47+
adjustFrame: PropTypes.func,
4748
renderRow: PropTypes.func,
4849
renderSeparator: PropTypes.func,
4950

@@ -170,7 +171,6 @@ export default class ModalDropdown extends Component {
170171
_renderModal() {
171172
if (this.state.showDropdown && this._buttonFrame) {
172173
let frameStyle = this._calcPosition();
173-
console.log(`frameStyle={width:${frameStyle.width}, height:${frameStyle.height}, top:${frameStyle.top}, left:${frameStyle.left}}`);
174174
return (
175175
<Modal animationType='fade'
176176
transparent={true}
@@ -216,6 +216,10 @@ export default class ModalDropdown extends Component {
216216
style.right = rightSpace - this._buttonFrame.w;
217217
}
218218

219+
if (this.props.adjustFrame) {
220+
style = this.props.adjustFrame(style) || style;
221+
}
222+
219223
return style;
220224
}
221225

example/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Demo extends Component {
7070
<ModalDropdown ref={el => this._dropdown_3 = el}
7171
style={styles.dropdown_3}
7272
options={DEMO_OPTIONS_1}
73+
adjustFrame={style => this._dropdown_3_adjustFrame(style)}
7374
/>
7475
</ScrollView>
7576
</View>
@@ -141,6 +142,13 @@ class Demo extends Component {
141142
/>);
142143
}
143144

145+
_dropdown_3_adjustFrame(style) {
146+
console.log(`frameStyle={width:${style.width}, height:${style.height}, top:${style.top}, left:${style.left}}`);
147+
style.top -= 15;
148+
style.left += 150;
149+
return style;
150+
}
151+
144152
_dropdown_4_willShow() {
145153
setTimeout(() => this.setState({
146154
dropdown_4_options: DEMO_OPTIONS_1,
@@ -156,6 +164,7 @@ class Demo extends Component {
156164
}
157165

158166
_dropdown_4_onSelect(idx, value) {
167+
// BUG: alert in a modal will auto dismiss and causes crash after reload and touch. @sohobloo 2016-12-1
159168
alert(`idx=${idx}, value='${value}'`);
160169
}
161170

0 commit comments

Comments
 (0)