-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Changes our property access pattern to iterate through props once and pass the Object value directly rather than looking the value up in the map with the key. Note some ViewManagers methods (especially yoga related ones on shadow nodes) expect a `Dyanamic`, so this diff also creates Dynamic's only when needed by the hand-written code, and introduces a new `DynamicWithObject` to create them that simply wraps the underlying object (as opposed to `DynamicWithMap` which wraps the map and does a lookup any time the `Dynamic` is accessed. Reviewed By: mdvacca Differential Revision: D14453300 fbshipit-source-id: df98567b6eff1e6b7c611f179eb11e413fb94e5d
- Loading branch information
1 parent
af38a0c
commit a46fba5
Showing
8 changed files
with
419 additions
and
243 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
ReactAndroid/src/main/java/com/facebook/react/bridge/DynamicFromObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.bridge; | ||
|
||
import com.facebook.common.logging.FLog; | ||
import com.facebook.react.common.ReactConstants; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Implementation of Dynamic wrapping a ReadableArray. | ||
*/ | ||
public class DynamicFromObject implements Dynamic { | ||
private @Nullable Object mObject; | ||
|
||
public DynamicFromObject(@Nullable Object obj) { | ||
mObject = obj; | ||
} | ||
|
||
@Override | ||
public void recycle() { | ||
// Noop - nothing to recycle since there is no pooling | ||
} | ||
|
||
@Override | ||
public boolean isNull() { | ||
return mObject == null; | ||
} | ||
|
||
@Override | ||
public boolean asBoolean() { | ||
return (boolean)mObject; | ||
} | ||
|
||
@Override | ||
public double asDouble() { | ||
return (double)mObject; | ||
} | ||
|
||
@Override | ||
public int asInt() { | ||
// Numbers from JS are always Doubles | ||
return ((Double)mObject).intValue(); | ||
} | ||
|
||
@Override | ||
public String asString() { | ||
return (String)mObject; | ||
} | ||
|
||
@Override | ||
public ReadableArray asArray() { | ||
return (ReadableArray)mObject; | ||
} | ||
|
||
@Override | ||
public ReadableMap asMap() { | ||
return (ReadableMap)mObject; | ||
} | ||
|
||
@Override | ||
public ReadableType getType() { | ||
if (isNull()) { | ||
return ReadableType.Null; | ||
} | ||
if (mObject instanceof Boolean) { | ||
return ReadableType.Boolean; | ||
} | ||
if (mObject instanceof Number) { | ||
return ReadableType.Number; | ||
} | ||
if (mObject instanceof String) { | ||
return ReadableType.String; | ||
} | ||
if (mObject instanceof ReadableMap) { | ||
return ReadableType.Map; | ||
} | ||
if (mObject instanceof ReadableArray) { | ||
return ReadableType.Array; | ||
} | ||
FLog.e(ReactConstants.TAG, "Unmapped object type " + mObject.getClass().getName()); | ||
return ReadableType.Null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.