mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix Android implementation for Linking.sendIntent()
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
46ab59c881
commit
86f8d0bb52
@@ -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);
|
||||
}
|
||||
@@ -184,13 +186,13 @@ public class IntentModule extends NativeIntentAndroidSpec {
|
||||
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:
|
||||
@@ -198,13 +200,13 @@ public class IntentModule extends NativeIntentAndroidSpec {
|
||||
// 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:
|
||||
|
||||
Reference in New Issue
Block a user