Add support for RCTText under FlatUIImplementation

Summary: @public Initial version of FlatUIImplementation lacks any primitives support (such as RCTText, RCTImageView or RCTView). This diff add the first part, RCTText (alongside with RCTVirtualText and RCTRawText).

Reviewed By: sriramramani

Differential Revision: D2693348
This commit is contained in:
Denis Koroskin
2015-12-06 16:00:36 -08:00
committed by Ahmed El-Helw
parent 44d2ee1c3f
commit 5c2f536e9a
21 changed files with 1466 additions and 20 deletions

View File

@@ -0,0 +1,108 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.flat;
/**
* Base class for all DrawCommands. Becomes immutable once it has its bounds set. Until then, a
* subclass is able to mutate any of its properties (e.g. updating Layout in DrawTextLayout).
*
* The idea is to be able to reuse unmodified objects when we build up DrawCommands before we ship
* them to UI thread, but we can only do that if DrawCommands are immutable.
*/
/* package */ abstract class AbstractDrawCommand implements DrawCommand, Cloneable {
private float mLeft;
private float mTop;
private float mRight;
private float mBottom;
private boolean mFrozen;
/**
* Updates boundaries of the AbstractDrawCommand and freezes it.
* Will return a frozen copy if the current AbstractDrawCommand cannot be mutated.
*/
public final AbstractDrawCommand updateBoundsAndFreeze(
float left,
float top,
float right,
float bottom) {
if (mFrozen) {
// see if we can reuse it
if (boundsMatch(left, top, right, bottom)) {
return this;
}
try {
AbstractDrawCommand copy = (AbstractDrawCommand) clone();
copy.setBounds(left, top, right, bottom);
return copy;
} catch (CloneNotSupportedException e) {
// This should not happen since AbstractDrawCommand implements Cloneable
throw new RuntimeException(e);
}
}
setBounds(left, top, right, bottom);
mFrozen = true;
return this;
}
/**
* Returns whether this object was frozen and thus cannot be mutated.
*/
public final boolean isFrozen() {
return mFrozen;
}
/**
* Left position of this DrawCommand relative to the hosting View.
*/
public final float getLeft() {
return mLeft;
}
/**
* Top position of this DrawCommand relative to the hosting View.
*/
public final float getTop() {
return mTop;
}
/**
* Right position of this DrawCommand relative to the hosting View.
*/
public final float getRight() {
return mRight;
}
/**
* Bottom position of this DrawCommand relative to the hosting View.
*/
public final float getBottom() {
return mBottom;
}
/**
* Updates boundaries of this DrawCommand.
*/
private void setBounds(float left, float top, float right, float bottom) {
mLeft = left;
mTop = top;
mRight = right;
mBottom = bottom;
}
/**
* Returns true if boundaries match and don't need to be updated. False otherwise.
*/
private boolean boundsMatch(float left, float top, float right, float bottom) {
return mLeft == left && mTop == top && mRight == right && mBottom == bottom;
}
}