Skip to content

Commit 04564a0

Browse files
vonovakfacebook-github-bot
authored andcommitted
allow overriding spannedFromShadowNode in ReactTextInputShadowNode (facebook#24995)
Summary: Motivation is the same as in facebook#24927 - when building a custom textinput (eg with rich text editing), one needs custom text processing logic. `ReactTextInputShadowNode` contains https://github.com/facebook/react-native/blob/6671165f69e37a49af8b709b4807f9049f7606c3/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java#L211 where an instance of `ReactTextUpdate` is created. For the custom use case, we'd like to just change the usage of [`spannedFromShadowNode()`](https://github.com/facebook/react-native/blob/6671165f69e37a49af8b709b4807f9049f7606c3/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java#L217) to our own implementation. from there: It's easy to subclass `ReactTextInputShadowNode` and override `public void onCollectExtraUpdates()` but the problem is that the method accesses private members. It also means overriding more code than necessary as we only care for `spannedFromShadowNode()`. Solution might be changing the members to protected, but that seemed weird because there are already setters for them. Creating getters also seemed weird, as we'd end up having unused getters hanging around. So the second way which I find nicer is changing `protected static Spannable spannedFromShadowNode(ReactBaseTextShadowNode textShadowNode, String text)` to just `protected` since that will allow subclasses to override just this behavior. ## Changelog [Android] [Added] - allow custom spannedFromShadowNode in ReactTextInputShadowNode subclasses Pull Request resolved: facebook#24995 Differential Revision: D15468066 Pulled By: cpojer fbshipit-source-id: 73d5f0b9e06f3e02a03bf9db5effac62cecc80c4
1 parent 82771f4 commit 04564a0

File tree

2 files changed

+1
-6
lines changed

2 files changed

+1
-6
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private static void buildSpannedFromShadowNode(
226226
}
227227

228228
// `nativeViewHierarchyOptimizer` can be `null` as long as `supportsInlineViews` is `false`.
229-
protected static Spannable spannedFromShadowNode(
229+
protected Spannable spannedFromShadowNode(
230230
ReactBaseTextShadowNode textShadowNode,
231231
String text,
232232
boolean supportsInlineViews,

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@
1818
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
1919
import com.facebook.react.bridge.ReadableMap;
2020
import com.facebook.react.common.annotations.VisibleForTesting;
21-
import com.facebook.react.uimanager.LayoutShadowNode;
22-
import com.facebook.react.uimanager.NativeViewHierarchyOptimizer;
23-
import com.facebook.react.uimanager.PixelUtil;
24-
import com.facebook.react.uimanager.ReactShadowNodeImpl;
2521
import com.facebook.react.uimanager.Spacing;
2622
import com.facebook.react.uimanager.ThemedReactContext;
2723
import com.facebook.react.uimanager.UIViewOperationQueue;
28-
import com.facebook.react.uimanager.ViewDefaults;
2924
import com.facebook.react.uimanager.annotations.ReactProp;
3025
import com.facebook.react.views.text.ReactBaseTextShadowNode;
3126
import com.facebook.react.views.text.ReactTextUpdate;

0 commit comments

Comments
 (0)