Skip to content

Commit

Permalink
Fix Android implementation for Linking.sendIntent()
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[Android][Fixed] - Fix Extras usage in Android implementation of Linking.sendIntent()

The implementation of sendIntent() has a bug in a way it uses extras map.

From JS layer the API sends and array of map, where each map contains exactly 2 entries: {"key" -> "name_of_extra_to_use", "value" -> value_of_extra_to_use}

However Java parsing was just picking a random pair out of this map and was sending it as extra.

Most frequently the result was "value" -> value_of_extra_to_use in Intent instead of name_of_extra_to_use -> value_of_extra_to_use

This diff fixes the problem

Reviewed By: lunaleaps

Differential Revision: D35516496

fbshipit-source-id: 7da0a1cb3b8aa30463004dbb47008c83d8e95bd1
  • Loading branch information
Vladyslav Stepanov authored and facebook-github-bot committed Apr 12, 2022
1 parent 46ab59c commit 86f8d0b
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class IntentModule extends NativeIntentAndroidSpec {

public static final String NAME = "IntentAndroid";

private static final String EXTRA_MAP_KEY_FOR_VALUE = "value";

public IntentModule(ReactApplicationContext reactContext) {
super(reactContext);
}
Expand Down Expand Up @@ -184,27 +186,27 @@ public void sendIntent(String action, @Nullable ReadableArray extras, Promise pr
if (extras != null) {
for (int i = 0; i < extras.size(); i++) {
ReadableMap map = extras.getMap(i);
String name = map.keySetIterator().nextKey();
ReadableType type = map.getType(name);
String name = map.getString("key");
ReadableType type = map.getType(EXTRA_MAP_KEY_FOR_VALUE);

switch (type) {
case String:
{
intent.putExtra(name, map.getString(name));
intent.putExtra(name, map.getString(EXTRA_MAP_KEY_FOR_VALUE));
break;
}
case Number:
{
// We cannot know from JS if is an Integer or Double
// See: https://github.com/facebook/react-native/issues/4141
// We might need to find a workaround if this is really an issue
Double number = map.getDouble(name);
Double number = map.getDouble(EXTRA_MAP_KEY_FOR_VALUE);
intent.putExtra(name, number);
break;
}
case Boolean:
{
intent.putExtra(name, map.getBoolean(name));
intent.putExtra(name, map.getBoolean(EXTRA_MAP_KEY_FOR_VALUE));
break;
}
default:
Expand Down

0 comments on commit 86f8d0b

Please sign in to comment.