Skip to content

Commit fb66992

Browse files
Patrick Kayongocooperka
authored andcommitted
Added Snackbar actions for android
1 parent 7bc6b4b commit fb66992

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

android/src/main/java/com/azendoo/reactnativesnackbar/SnackbarModule.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,20 @@ public void show(ReadableMap options, Callback callback) {
4646
String title = options.hasKey("title") ? options.getString("title") : "Hello";
4747
int duration = options.hasKey("duration") ? options.getInt("duration") : Snackbar.LENGTH_SHORT;
4848

49-
Snackbar
50-
.make(view, title, duration)
51-
.show();
49+
Snackbar snackbar = Snackbar.make(view, title, duration);
50+
if (options.hasKey("action")) {
51+
View.OnClickListener onClickListener = new View.OnClickListener() {
52+
@Override
53+
public void onClick(View v) {
54+
callback.invoke();
55+
}
56+
};
57+
58+
ReadableMap actionDetails = options.getMap("action");
59+
snackbar.setAction(actionDetails.getString("title"), onClickListener);
60+
snackbar.setActionTextColor(actionDetails.getInt("color"));
61+
}
62+
63+
snackbar.show();
5264
}
5365
}

0 commit comments

Comments
 (0)