Skip to content

Commit 56bf1f0

Browse files
committed
Merge branch 'master' into safe-area
2 parents 3b4e153 + e164602 commit 56bf1f0

7 files changed

Lines changed: 24 additions & 17 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Features:
1515
* RTL layout support
1616

1717
Community driven features:
18-
* Support for UWP and react-native-web
18+
* Support for UWP, react-native-web and react-native-desktop
1919
* Typescript definitions
2020

2121
We thank our community for maintaining features that goes over our scope.

__tests__/helpers-test.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,9 @@ describe('helpers test', () => {
7070
expect(defaultTouchableProps).to.be.an('object');
7171
});
7272

73-
it('should create TouchableHighlight for web', () => {
73+
it('should create TouchableHighlight for default', () => {
7474
Platform.select.mockImplementationOnce(o => {
75-
return o.web;
76-
});
77-
const { Touchable, defaultTouchableProps } = makeTouchable();
78-
expect(Touchable).to.be.equal(TouchableHighlight);
79-
expect(defaultTouchableProps).to.be.an('object');
80-
});
81-
82-
it('should create TouchableHighlight for windows', () => {
83-
Platform.select.mockImplementationOnce(o => {
84-
return o.windows;
75+
return o.default;
8576
});
8677
const { Touchable, defaultTouchableProps } = makeTouchable();
8778
expect(Touchable).to.be.equal(TouchableHighlight);

doc/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The only known exception is when you use [Modal](https://facebook.github.io/reac
2424
|`style`|`Style`|Optional||Style of wrapping `View` component. Same as `customStyles.menuProviderWrapper` but when both are present result style is a merge where this style has higher precedence.|
2525
|`customStyles`|`Object`|Optional||Object defining wrapper, touchable and text styles|
2626
|`backHandler`|`boolean\|Function`|Optional|false|Whether to close the menu when the back button is pressed or custom back button handler if a function is passed (RN >= 0.44 is required)|
27+
|`skipInstanceCheck`|`boolean`|Optional|false|Normally your application should have only one menu provider (with exception as discussed above). If you really need more instances, set `skipInstanceCheck` to `true` to disable the check (and following warning message)|
2728

2829
### Custom styles
2930

examples/ModalExample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ModalExample extends Component {
2525
</MenuOptions>
2626
</Menu>
2727
<Modal visible={this.state.visible} onRequestClose={() => this.setState({ visible: false })}>
28-
<MenuProvider style={{flexDirection: 'column', padding: 30, backgroundColor: 'white'}}>
28+
<MenuProvider skipInstanceCheck style={{flexDirection: 'column', padding: 30, backgroundColor: 'white'}}>
2929
<Text>Modal window:</Text>
3030
<Menu onSelect={value => alert(`Selected number: ${value}`)}>
3131
<MenuTrigger text='Select option' />

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-popup-menu",
3-
"version": "0.13.2",
3+
"version": "0.13.3",
44
"description": "extensible popup/context menu for react native",
55
"main": "src/index.js",
66
"directories": {

src/MenuProvider.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ if (!React.forwardRef) {
2222
export const PopupMenuContext = createContext({})
2323
export const withCtx = withContext(PopupMenuContext, "ctx");
2424

25+
// count of MenuProvider instances
26+
let instanceCount = 0;
27+
2528
export default class MenuProvider extends Component {
2629

2730
constructor(props) {
@@ -68,16 +71,27 @@ export default class MenuProvider extends Component {
6871
console.warn('backHandler prop cannot be used if BackHandler is not present (RN >= 0.44 required)');
6972
}
7073
}
71-
if (this.props.customStyles.menuContextWrapper) {
74+
const { customStyles, skipInstanceCheck } = this.props;
75+
if (customStyles.menuContextWrapper) {
7276
console.warn('menuContextWrapper custom style is deprecated and it might be removed in future releases, use menuProviderWrapper instead.');
7377
}
78+
if (!skipInstanceCheck) {
79+
instanceCount++;
80+
}
81+
if (instanceCount > 1) {
82+
console.warn('In most cases you should not have more MenuProviders in your app (see API documentation). In other cases use skipInstanceCheck prop.');
83+
}
7484
}
7585

7686
componentWillUnmount() {
7787
debug('unmounting menu provider')
7888
if (BackHandler) {
7989
BackHandler.removeEventListener('hardwareBackPress', this._handleBackButton);
8090
}
91+
const { skipInstanceCheck } = this.props;
92+
if (!skipInstanceCheck) {
93+
instanceCount--;
94+
}
8195
}
8296

8397
isMenuOpen() {
@@ -335,11 +349,13 @@ export default class MenuProvider extends Component {
335349
MenuProvider.propTypes = {
336350
customStyles: PropTypes.object,
337351
backHandler: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
352+
skipInstanceCheck: PropTypes.bool,
338353
}
339354

340355
MenuProvider.defaultProps = {
341356
customStyles: {},
342357
backHandler: false,
358+
skipInstanceCheck: false,
343359
};
344360

345361
const styles = StyleSheet.create({

src/helpers.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ export function makeTouchable(TouchableComponent) {
2929
const Touchable = TouchableComponent || Platform.select({
3030
android: TouchableNativeFeedback,
3131
ios: TouchableHighlight,
32-
web: TouchableHighlight,
33-
windows:TouchableHighlight,
32+
default: TouchableHighlight,
3433
});
3534
let defaultTouchableProps = {};
3635
if (Touchable === TouchableHighlight) {

0 commit comments

Comments
 (0)