Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions android/src/main/java/com/actionsheet/ActionSheetModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ public void showActionSheetWithOptions(final ReadableMap options, final Callback

final List<String> titles = new ArrayList<String>();

int _cancelInde = 99;
if (options.hasKey("cancelButtonIndex")) {
_cancelInde = options.getInt("cancelButtonIndex");
}
final int cancelIndex = _cancelInde;
if (options.hasKey("options")) {
ReadableArray customButtons = options.getArray("options");
for (int i = 0; i < customButtons.size(); i++) {
int currentIndex = titles.size();
titles.add(currentIndex, customButtons.getString(i));
if (i != cancelIndex) {
titles.add(currentIndex, customButtons.getString(i));
}
}
}

Expand All @@ -60,7 +67,11 @@ public void showActionSheetWithOptions(final ReadableMap options, final Callback

builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int index) {
callback.invoke(index);
if (index < cancelIndex) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if cancelIndex = 1 and index = 2 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's ok. The code keeps title and it's index same with pass in.
While an other bug is cancelIndex can't be -1 as default, change to
int _cancelInde = 99;

callback.invoke(index);
} else {
callback.invoke(index + 1);
}
}
});

Expand All @@ -73,7 +84,6 @@ public void onClick(DialogInterface dialog, int index) {
@Override
public void onCancel(DialogInterface dialog) {
dialog.dismiss();
callback.invoke();
}
});
dialog.show();
Expand Down