8000 Keep js invoke code same with iOS. by anysome · Pull Request #2 · yfuks/react-native-action-sheet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Keep js invoke code same with iOS. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
0