dominicstop / react-native-ios-context-menu

A react-native component to use context menu's (UIMenu) on iOS 13/14+
MIT License
544 stars 25 forks source link

Android TypeError: Cannot read property 'Commands' of undefined #29

Closed adorum closed 2 years ago

adorum commented 2 years ago

@dominicstop Based on docs, ContextMenuView should render regular View component on Android. My android app crash with an error TypeError: Cannot read property 'Commands' of undefined at the moment of import {ContextMenuView} from 'react-native-ios-context-menu'. I conditionally render the component which contains this import statement only for ios platform.

Any suggestions?

nandorojo commented 2 years ago

Until it's fixed, you could re-export an empty view inside of your own file, such as: context-menu.android.tsx:

context-menu.tsx

export { ContextMenuView } from 'react-native-ios-context-menu'

context-menu.android.tsx

import { View } from 'react-native'

export const ContextMenuView = View

And then, in any file, just do:

import { ContextMenuView } from './context-menu'
adorum commented 2 years ago

Thanks @nandorojo. Worked like a charm! Just can't find out why its working on android by default (w/o your suggestion) in the example project of this repo. Anyway thanks :)

dominicstop commented 2 years ago

hi, thanks for creating this issue ✨

sorry it took so long @adorum, but i implemented @nandorojo recommendation in the latest 1.7.1 patch haha

i used to use *.ios.js/*.android.js in an older version of this library (i.e. v1.3.0), but i forgot to add it back during the typescript re-write (due to metro + typescript-related bugs).

hopefully the latest patch fixes this (unfortunately, i don't have enough space to install android studio, so i can't verify if this fixes the bug haha)

Edit: So it turns out that platform extensions + typescript can get pretty messy real quick. In the next patch I'll be using platform specific exports instead to fix this bug.

dominicstop commented 2 years ago

this has now been fixed in v1.7.2 patch
screenshot: Screen Shot 2022-01-02 at 2 59 10 PM
please re-open this issue if this patch doesn't fix the issue haha