|
1 | 1 | import React, { PureComponent } from 'react'; |
2 | | -import { Keyboard, Modal, Platform, Text, TextInput, TouchableOpacity, View } from 'react-native'; |
| 2 | +import { |
| 3 | + Dimensions, |
| 4 | + Keyboard, |
| 5 | + Modal, |
| 6 | + Platform, |
| 7 | + Text, |
| 8 | + TextInput, |
| 9 | + TouchableOpacity, |
| 10 | + View, |
| 11 | +} from 'react-native'; |
3 | 12 | import PropTypes from 'prop-types'; |
4 | 13 | import isEqual from 'lodash.isequal'; |
5 | 14 | import { Picker } from '@react-native-picker/picker'; |
6 | 15 | import { defaultStyles } from './styles'; |
7 | | -import { Dimensions } from 'react-native'; |
8 | 16 | import { PickerAvoidingView } from './PickerAvoidingView'; |
9 | 17 | import { PickerStateContext, PickerStateProvider } from './PickerStateProvider'; |
10 | | -import { IOS_MODAL_HEIGHT } from './constants'; |
| 18 | +import { IOS_MODAL_ANIMATION_DURATION_MS, IOS_MODAL_HEIGHT } from './constants'; |
11 | 19 |
|
12 | 20 | const preserveSpaces = (label) => { |
13 | 21 | return label.replace(/ /g, '\u00a0'); |
@@ -245,9 +253,13 @@ export default class RNPickerSelect extends PureComponent { |
245 | 253 |
|
246 | 254 | // If TextInput is below picker modal, scroll up |
247 | 255 | if (textInputBottomY > modalY) { |
248 | | - this.props.scrollViewRef.current.scrollTo({ |
249 | | - y: textInputBottomY - modalY + this.props.scrollViewContentOffsetY, |
250 | | - }); |
| 256 | + // Wait until the modal animation finishes, so the scrolling is effective when PickerAvoidingView is |
| 257 | + // used |
| 258 | + setTimeout(() => { |
| 259 | + this.props.scrollViewRef.current.scrollTo({ |
| 260 | + y: textInputBottomY - modalY + 10 + this.props.scrollViewContentOffsetY, |
| 261 | + }); |
| 262 | + }, IOS_MODAL_ANIMATION_DURATION_MS + 50); |
251 | 263 | } |
252 | 264 | }); |
253 | 265 | } |
|
0 commit comments