question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ActionSheetProvider in place, class actionSheet works, hook actionSheet does not work.

See original GitHub issue

I have an ActionSheetProvider that works and is in App.tsx. In many class component the actionSheet works, however in a functional component using the hook it doesn’t.

I was trying to make sure I followed correctly the docs.

App.tsx CleanShot 2020-08-16 at 14 51 18@2x

In my functional component:


const { showActionSheetWithOptions } = useActionSheet();

const openActionSheet = (document: {}) =>
    showActionSheetWithOptions(
      {
        options,
        cancelButtonIndex,
      },
      (buttonIndex) => {
        switch (buttonIndex) {
          case 0:
            pickImageAsync(
              onDocumentPicker,
              document != null
                ? document
                : { document: { documentType: "foto" } }
            );
            return;
          case 1:
            takePictureAsync(
              onDocumentPicker,
              document != null
                ? {
                    document,
                  }
                : null
            );
            return;
          case 2:
            chooseFileAsync(
              onDocumentPicker,
              document != null
                ? {
                    document,
                  }
                : null
            );
            return;
          default:
        }
      }
    );

The action gets fired but nothing happens. Any help would be appreciated. Since the examples in the doc explain how to use the hook in app.tsx I’m not sure if the hook should be used directly in a functional component or if it is an alternative to the <ActionSheetProvider /> HOC

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
superandrewcommented, Sep 2, 2020

unfortunately no, I didn’t. I’m sure there is an explanation, however I am forced to embed the component inside the tag to make it work on the functional component.

0reactions
yybot1commented, Jan 11, 2021

I encountered a similar problem, and eventually I noticed that the problem is related to the “react-native-navigation” library I used. If you use any navigation libraries, then just wrap top-level component with ActionSheetProvider may not work.

For “react-native-navigation”, I have to wrap each component separately using Navigation.registerComponent()

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use react-native-action-sheet with hooks
I'm already using the class components version without any problem but I'd like to switch to functional. React version is 16.9.0. This is...
Read more >
exponentjs - Bountysource
Hi,. I would like to open this issue because I had some trouble with my app. ActionSheet.showActionSheetWithOptions( { options, } ...
Read more >
ActionSheet provider and hook in React Native - YouTube
In this video I'll show how we can create an actionsheet provider and react hook using the native base actionsheet. This will save...
Read more >
Ionic 4 Action Sheet Tutorial - YouTube
By the end of this tutorial, the ionic 4 action sheet will be no match for you! Please LIKE and SUB if this...
Read more >
A cross-platform ActionSheet for React Native - Morioh
ActionSheet is a cross-platform React Native component that uses the native UIActionSheet on iOS and a JS implementation on Android.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found