Skip to content

Commit 254d8f4

Browse files
authored
fixAndroidTouchableBug (lawnstarter#377)
1 parent 866de0d commit 254d8f4

File tree

7 files changed

+43
-6
lines changed

7 files changed

+43
-6
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
CC_TEST_REPORTER_ID: 9b36beb22e04451e6414fcc28926f995c253d94877f616b50d192255196fbb68
1010
docker:
1111
# specify the version you desire here
12-
- image: circleci/node:10.16.0-stretch-browsers
12+
- image: circleci/node:12.19.0-stretch-browsers
1313

1414
# Specify service dependencies here if necessary
1515
# CircleCI maintains a library of pre-built images

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 8.0.2
2+
3+
##### Bugfix
4+
5+
- Add `fixAndroidTouchableBug` prop (#354)
6+
7+
---
8+
19
## 8.0.1
210

311
##### Bugfix

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ npx pod-install
3535
expo install @react-native-community/picker
3636
```
3737

38-
3938
### Basic Usage
4039

4140
```js
@@ -80,6 +79,7 @@ export const Dropdown = () => {
8079
| `touchableWrapperProps` | Additional props to pass to the touchable wrapping the TextInput (some props are used in core functionality so use this carefully) | object |
8180
| `onOpen`<br> | Callback triggered right before the opening of the picker<br>_Not supported when `useNativeAndroidPickerStyle={true}`_ | function |
8281
| `useNativeAndroidPickerStyle`<br>_Android only_ | The component defaults to using the native Android Picker in its un-selected state. Setting this flag to `false` will mimic the default iOS presentation where a tappable TextInput is displayed.<br>_More details in [styling](#styling)_ | boolean |
82+
| `fixAndroidTouchableBug`<br>_Android only_ | Experimental flag to fix issue [#354](https://github.com/lawnstarter/react-native-picker-select/issues/354) | boolean |
8383
| `InputAccessoryView`<br>_iOS only_ | Replace the InputAcessoryView section (bar with tabbing arrown and Done button) of the opened picker with your own custom component. Can also return `null` here to hide completely. While this bar is typical on `select` elements on the web, the [interface guidelines](https://developer.apple.com/ios/human-interface-guidelines/controls/pickers/) does not include it. View the [snack](https://snack.expo.io/@lfkwtz/react-native-picker-select) to see examples on how this can be customized. | Component |
8484
| `doneText`<br>_iOS only_ | "Done" default text on the modal. Can be overwritten here | string |
8585
| `onUpArrow / onDownArrow`<br>_iOS only_ | Presence enables the corresponding arrow<br>- Closes the picker<br>- Calls the callback provided | function |

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface PickerSelectProps {
7272
children?: React.ReactNode;
7373
onOpen?: () => void;
7474
useNativeAndroidPickerStyle?: boolean;
75+
fixAndroidTouchableBug?: boolean;
7576
doneText?: string;
7677
onDonePress?: () => void;
7778
onUpArrow?: () => void;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-picker-select",
3-
"version": "8.0.1",
3+
"version": "8.0.2",
44
"description": "A Picker component for React Native which emulates the native <select> interfaces for each platform",
55
"license": "MIT",
66
"author": "Michael Lefkowitz <[email protected]>",

src/index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default class RNPickerSelect extends PureComponent {
3030
children: PropTypes.any, // eslint-disable-line react/forbid-prop-types
3131
onOpen: PropTypes.func,
3232
useNativeAndroidPickerStyle: PropTypes.bool,
33+
fixAndroidTouchableBug: PropTypes.bool,
3334

3435
// Custom Modal props (iOS only)
3536
doneText: PropTypes.string,
@@ -70,6 +71,7 @@ export default class RNPickerSelect extends PureComponent {
7071
style: {},
7172
children: null,
7273
useNativeAndroidPickerStyle: true,
74+
fixAndroidTouchableBug: false,
7375
doneText: 'Done',
7476
onDonePress: null,
7577
onUpArrow: null,
@@ -469,11 +471,20 @@ export default class RNPickerSelect extends PureComponent {
469471
}
470472

471473
renderAndroidHeadless() {
472-
const { disabled, Icon, style, pickerProps, onOpen, touchableWrapperProps } = this.props;
474+
const {
475+
disabled,
476+
Icon,
477+
style,
478+
pickerProps,
479+
onOpen,
480+
touchableWrapperProps,
481+
fixAndroidTouchableBug,
482+
} = this.props;
473483
const { selectedItem } = this.state;
474484

485+
const Component = fixAndroidTouchableBug ? View : TouchableOpacity;
475486
return (
476-
<TouchableOpacity
487+
<Component
477488
testID="android_touchable_wrapper"
478489
onPress={onOpen}
479490
activeOpacity={1}
@@ -496,7 +507,7 @@ export default class RNPickerSelect extends PureComponent {
496507
{this.renderPickerItems()}
497508
</Picker>
498509
</View>
499-
</TouchableOpacity>
510+
</Component>
500511
);
501512
}
502513

@@ -560,6 +571,7 @@ export default class RNPickerSelect extends PureComponent {
560571
if (children || !useNativeAndroidPickerStyle) {
561572
return this.renderAndroidHeadless();
562573
}
574+
563575
return this.renderAndroidNativePickerStyle();
564576
}
565577
}

test/test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,22 @@ describe('RNPickerSelect', () => {
386386
expect(onOpenSpy).toHaveBeenCalledWith();
387387
});
388388

389+
it('should use a View when fixAndroidTouchableBug=true (Android)', () => {
390+
Platform.OS = 'android';
391+
const wrapper = shallow(
392+
<RNPickerSelect
393+
items={selectItems}
394+
onValueChange={noop}
395+
useNativeAndroidPickerStyle={false}
396+
fixAndroidTouchableBug
397+
/>
398+
);
399+
400+
const touchable = wrapper.find('[testID="android_touchable_wrapper"]');
401+
402+
expect(touchable.type().displayName).toEqual('View');
403+
});
404+
389405
it('should call the onClose callback when set', () => {
390406
Platform.OS = 'ios';
391407
const onCloseSpy = jest.fn();

0 commit comments

Comments
 (0)