|
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 | export default class RNPickerSelect extends PureComponent { |
13 | 21 | static contextType = PickerStateContext; |
@@ -240,9 +248,13 @@ export default class RNPickerSelect extends PureComponent { |
240 | 248 |
|
241 | 249 | // If TextInput is below picker modal, scroll up |
242 | 250 | if (textInputBottomY > modalY) { |
243 | | - this.props.scrollViewRef.current.scrollTo({ |
244 | | - y: textInputBottomY - modalY + this.props.scrollViewContentOffsetY, |
245 | | - }); |
| 251 | + // Wait until the modal animation finishes, so the scrolling animation doesn't run at the same time as |
| 252 | + // the modal animation. This prevents jiggering if PickerAvoidingView is used. |
| 253 | + setTimeout(() => { |
| 254 | + this.props.scrollViewRef.current.scrollTo({ |
| 255 | + y: textInputBottomY - modalY + 10 + this.props.scrollViewContentOffsetY, |
| 256 | + }); |
| 257 | + }, IOS_MODAL_ANIMATION_DURATION_MS); |
246 | 258 | } |
247 | 259 | }); |
248 | 260 | } |
|
0 commit comments