prscX / react-native-bottom-action-sheet

React Native: Native Bottom Action Sheet
Apache License 2.0
633 stars 48 forks source link

undefined is not an object (evaluating 'RNBottomActionSheet.SheetView') #24

Closed stefblokdijk closed 4 years ago

stefblokdijk commented 6 years ago

Hey,

I just installed the package using the following npm command npm install react-native-bottom-action-sheet --save --ignore-scripts Because it was stuck on executing pod install command. Since i'll only use this plugin for Android, i guess the pods are not needed. But i did link the package and edit the build.gradle

So on Android, I get this error: undefined is not an object (evaluating 'RNBottomActionSheet.SheetView') its coming from SheetView.js:76:24 according to my error message

This is my code:

/**
 * Determine how to show action sheet
 */
Platform.select({
  ios: () => ActionSheetIOS.showActionSheetWithOptions({
        options: ['See details', 'Preview', 'Copy Link', 'Delete', 'Cancel'],
        destructiveButtonIndex: 3,
        cancelButtonIndex: 4,
    }, (buttonIndex) => {

      /**
       * Determine what to do based on click of the button
       */
      switch (buttonIndex) {

          //

      }

  }),
  android: () => RNBottomActionSheet.SheetView.Show({
      title: "Options",
      items: [
          {
              title: "Testing",
              value: 'test',
              subTitle: "Testing Description",
              icon: (<Icon family={'FontAwesome'} name={'instagram'} color={'#000000'} size={30} />),
          },
      ],
      theme: "light",
      selection: 3,
      onSelection: (index) => {

        // value is optional
        console.log("selection: " + index + " ");

      }
  })
})();

Hopefully you can help me

prscX commented 6 years ago

Thanks @stefblokdijk for raising the issue.

This error occurs when the library is not linked properly, basically at the shared line number it is trying to invoke native module API which apparently is undefined. Can you please validate the Android setup steps defined in the README.

Please let me know incase it does not works.

Thanks </ Pranav >

tuanngocptn commented 6 years ago

Hello prscX. I'm flowing 'Getting started' in your README file. and get the same error when I set 'state.sheetView' is true in IOS and working in Android. Thanks

rochapablo commented 6 years ago
\MainApplication.java:29: error: cannot find symbol
            new RNBottomActionSheetPackage(),
                ^
  symbol: class RNBottomActionSheetPackage
2 errors
 FAILED
Cannot load module file 'node_modules/react-native-bottom-action-sheet/android/react-native-bottom-action-sheet.iml':
File node_modules\react-native-bottom-action-sheet\android\react-native-bottom-action-sheet.iml does not exist
Would you like to remove module 'react-native-bottom-action-sheet' from the project?

settings.gradle

include ':react-native-bottom-action-sheet'
project(':react-native-bottom-action-sheet').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-bottom-action-sheet/android')

build.gradle


buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven { url 'https://jitpack.io' }
    }
}

app/build.gradle

dependencies {
    compile project(':react-native-vector-icons')
    compile project(':react-native-config')
    compile project(':react-native-bottom-action-sheet')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

MainApplication

@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new RNBottomActionSheetPackage(),
          new ReactNativeConfigPackage(),
          new VectorIconsPackage()
      );
    }

Versions

"react": "16.3.1",
"react-native": "~0.55.2",
"react-native-bottom-action-sheet": "^0.0.18",
"react-native-vector-icons": "^5.0.0",
arma7x commented 5 years ago

@rochapablo you miss import ui.bottomactionsheet.RNBottomActionSheetPackage; in MainApplication.java

arma7x commented 5 years ago

Problem solve for me, just missing a few line in MainApplication.java

prscX commented 4 years ago

Thanks @arma7x for sharing the fix. Closing the issue.

Thanks </ Pranav >