mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-05 17:30:38 +08:00
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:
committed by
Ahmed El-Helw
parent
44d2ee1c3f
commit
5c2f536e9a
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.View.MeasureSpec;
|
||||
|
||||
import com.facebook.react.uimanager.NativeViewHierarchyManager;
|
||||
import com.facebook.react.uimanager.SizeMonitoringFrameLayout;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.facebook.react.uimanager.ViewManagerRegistry;
|
||||
|
||||
/**
|
||||
* FlatNativeViewHierarchyManager is the only class that performs View manipulations. All of this
|
||||
* class methods can only be called from UI thread by {@link FlatUIViewOperationQueue}.
|
||||
*/
|
||||
/* package */ final class FlatNativeViewHierarchyManager extends NativeViewHierarchyManager {
|
||||
|
||||
/* package */ FlatNativeViewHierarchyManager(ViewManagerRegistry viewManagers) {
|
||||
super(viewManagers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRootView(
|
||||
int tag,
|
||||
SizeMonitoringFrameLayout view,
|
||||
ThemedReactContext themedContext) {
|
||||
FlatViewGroup root = new FlatViewGroup(themedContext);
|
||||
view.addView(root);
|
||||
|
||||
addRootViewGroup(tag, root, themedContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns new DrawCommands to a FlatViewGroup specified by a reactTag.
|
||||
*
|
||||
* @param reactTag reactTag to lookup FlatViewGroup by
|
||||
* @param drawCommands new draw commands to execute during the drawing.
|
||||
*/
|
||||
/* package */ void updateMountState(int reactTag, DrawCommand[] drawCommands) {
|
||||
FlatViewGroup view = (FlatViewGroup) resolveView(reactTag);
|
||||
view.mountDrawCommands(drawCommands);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates View bounds, possibly re-measuring and re-layouting it if the size changed.
|
||||
*
|
||||
* @param reactTag reactTag to lookup a View by
|
||||
* @param left left coordinate relative to parent
|
||||
* @param top top coordinate relative to parent
|
||||
* @param right right coordinate relative to parent
|
||||
* @param bottom bottom coordinate relative to parent
|
||||
*/
|
||||
/* package */ void updateViewBounds(int reactTag, int left, int top, int right, int bottom) {
|
||||
View view = resolveView(reactTag);
|
||||
int width = right - left;
|
||||
int height = bottom - top;
|
||||
if (view.getWidth() != width || view.getHeight() != height) {
|
||||
// size changed, we need to measure and layout the View
|
||||
view.measure(
|
||||
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
||||
view.layout(left, top, right, bottom);
|
||||
} else {
|
||||
// same size, only location changed, there is a faster route.
|
||||
view.offsetLeftAndRight(left - view.getLeft());
|
||||
view.offsetTopAndBottom(top - view.getTop());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user