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.

undefined in buttonIndex callback showActionSheetWithOptions

See original GitHub issue

Hi,

I would like to open this issue because I had some trouble with my app.

ActionSheet.showActionSheetWithOptions(
      {
        options,
      },
      (i) => {
        setSelectedKind(kinds[i]);
      }
    );

When my action sheet is displayed and I clicked on the return button of my emulator, the buttonIndex callback is triggered and I got parameter i as undefined that cause my app to crash. I thought that this parameter type was of type number: https://github.com/expo/react-native-action-sheet/blob/master/src/types.ts#L5

I also considered this pr: https://github.com/expo/react-native-action-sheet/pull/102, but I’m not sure to understand the point. Is it possible that this callback is not called if we click on the return button ? Are we obliged to put a cancel button on the action sheet to get the expected behavior ?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
bradbytecommented, Oct 14, 2021

🎉 This issue has been resolved in version 3.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

0reactions
pmgzocommented, Oct 24, 2021

In what cases can it be undefined? If cancelButtonIndex is passed, is it guaranteed it won’t be? Thanks!

What i wanted to say is just add the undefined type in typescript. Because the cancelButtonIndex is just acting at runtime. But yes, if you specify cancelButton it should work as expected !

Read more comments on GitHub >

github_iconTop Results From Across the Web

@scrawllife/react-native-action-sheet - npm
showActionSheetWithOptions ( { options: options ... hardware back button is pressed the buttonIndex value is cancelButtonIndex or 'undefined' ...
Read more >
exponentjs - Bountysource
When my action sheet is displayed and I clicked on the return button of my emulator, the buttonIndex callback is triggered and I...
Read more >
async/await and recursion - Stack Overflow
It returns undefined because there is a path where there is no return statement. ... showActionSheetWithOptions is not async.
Read more >
Javascript – async/await and recursion – iTecNote
showActionSheetWithOptions ({ title: 'Choose a value from array: ', options: object.array, }, buttonIndex => async function() { const selectedValue ...
Read more >
ActionSheetIOS - React Native
static showActionSheetWithOptions(options, callback). Display an iOS action ... showActionSheetWithOptions( ... if (buttonIndex === 1) {
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