mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 16:10:58 +00:00
add ability to save/access Activity instanceState from/to JS
Differential Revision: D2591821 fb-gh-sync-id: c9c28b653611e65ab5b6e6cc8d34771bf8589055
This commit is contained in:
parent
a2d58203b8
commit
28b66be7b0
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
package com.facebook.react.bridge;
|
package com.facebook.react.bridge;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
public class Arguments {
|
public class Arguments {
|
||||||
@ -139,4 +141,52 @@ public class Arguments {
|
|||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Covert a {@link WritableMap} to a {@link Bundle}.
|
||||||
|
* @param readableMap the {@link WritableMap} to convert.
|
||||||
|
* @return the converted {@link Bundle}.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static Bundle toBundle(@Nullable ReadableMap readableMap) {
|
||||||
|
if (readableMap == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
|
||||||
|
if (!iterator.hasNextKey()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
while (iterator.hasNextKey()) {
|
||||||
|
String key = iterator.nextKey();
|
||||||
|
ReadableType readableType = readableMap.getType(key);
|
||||||
|
switch (readableType) {
|
||||||
|
case Null:
|
||||||
|
bundle.putString(key, null);
|
||||||
|
break;
|
||||||
|
case Boolean:
|
||||||
|
bundle.putBoolean(key, readableMap.getBoolean(key));
|
||||||
|
break;
|
||||||
|
case Number:
|
||||||
|
// Can be int or double.
|
||||||
|
bundle.putDouble(key, readableMap.getDouble(key));
|
||||||
|
break;
|
||||||
|
case String:
|
||||||
|
bundle.putString(key, readableMap.getString(key));
|
||||||
|
break;
|
||||||
|
case Map:
|
||||||
|
bundle.putBundle(key, toBundle(readableMap.getMap(key)));
|
||||||
|
break;
|
||||||
|
case Array:
|
||||||
|
// TODO t8873322
|
||||||
|
throw new UnsupportedOperationException("Arrays aren't supported yet.");
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bundle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user