forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Enable views to be nested within <Text>
Potential breaking change: The signature of ReactShadowNode's onBeforeLayout method was changed - Before: public void onBeforeLayout() - After: public void onBeforeLayout(NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer) Depends on this css-layout PR: facebook/yoga#202 Implements same feature as this iOS PR: facebook#7304 Previously, only Text and Image could be nested within Text. Now, any view can be nested within Text. One restriction of this feature is that developers must give inline views a width and a height via the style prop. Previously, inline Images were supported via FrescoBasedReactTextInlineImageSpan. To get support for nesting views within Text, we create one special kind of span per inline view. This span is called TextInlineViewPlaceholderSpan. It is the same size as the inline view. Its job is just to occupy space -- it doesn't render any visual. After the text is rendered, we query the Android Layout object associated with the TextView to find out where it has positioned each TextInlineViewPlaceholderSpan. We then position the views to be at those locations. One tricky aspect of the implementation is that the Text component needs to be able to render native children (the inline views) but the Android TextView cannot have children. This is solved by having the native parent of the ReactTextView also host the inline views. Implementation-wise, this was accomplished by extending the NativeViewHierarchyOptimizer to handle this case. The optimizer now handles these cases: - Node is not in the native tree. An ancestor must host its children. - Node is in the native tree and it can host its own children. - (new) Node is in the native tree but it cannot host its own children. An ancestor must host both this node and its children. Limitation: Clipping ==== If Text's height/width is small such that an inline view doesn't completely fit, the inline view may still be fully visible due to hoisting (the inline view isn't actually parented to the Text which has the limited size. It is parented to an ancestor which may have a different clipping rectangle.). Prior to this change, layout-only views had a similar limitation.
- Loading branch information
Adam Comella
committed
Jul 20, 2016
1 parent
602098c
commit a49a4d9
Showing
16 changed files
with
481 additions
and
115 deletions.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
ReactAndroid/src/main/java/com/facebook/react/uimanager/IViewManagerWithChildren.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,24 @@ | ||
/** | ||
* 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.uimanager; | ||
|
||
public interface IViewManagerWithChildren { | ||
/** | ||
* Returns whether this View type needs to handle laying out its own children instead of | ||
* deferring to the standard css-layout algorithm. | ||
* Returns true for the layout to *not* be automatically invoked. Instead onLayout will be | ||
* invoked as normal and it is the View instance's responsibility to properly call layout on its | ||
* children. | ||
* Returns false for the default behavior of automatically laying out children without going | ||
* through the ViewGroup's onLayout method. In that case, onLayout for this View type must *not* | ||
* call layout on its children. | ||
*/ | ||
public boolean needsCustomLayoutForChildren(); | ||
} |
23 changes: 23 additions & 0 deletions
23
ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeKind.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,23 @@ | ||
/** | ||
* 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.uimanager; | ||
|
||
public enum NativeKind { | ||
// Node is in the native hierarchy and the HierarchyOptimizer should assume it can host children | ||
// (e.g. because it's a ViewGroup). Note that it's okay if the node doesn't support children. When | ||
// the HierarchyOptimizer generates children manipulation commands for that node, the | ||
// HierarchyManager will catch this case and throw an exception. | ||
PARENT, | ||
// Node is in the native hierarchy, it may have children, but it cannot host them itself (e.g. | ||
// because it isn't a ViewGroup). Consequently, its children need to be hosted by an ancestor. | ||
LEAF, | ||
// Node is not in the native hierarchy. | ||
NONE | ||
} |
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.