Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<3c2494d2482efe3dded741dd746d4309>>
* @generated SignedSource<<ee36d5882cffbab0dd6e10da8e20c744>>
*/

/**
Expand Down Expand Up @@ -48,6 +48,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun cxxNativeAnimatedEnabled(): Boolean = accessor.cxxNativeAnimatedEnabled()

/**
* When enabled, cached PreparedLayout objects are shared across ParagraphShadowNodes without creating new JNI global references for differing React tags; new React tags are attached via a local JNI reference on mount.
*/
@JvmStatic
public fun deferPreparedLayoutReactTagsToMountAndroid(): Boolean = accessor.deferPreparedLayoutReactTagsToMountAndroid()

/**
* When enabled, iOS TextInput applies edits that JS transforms (e.g. maxLength truncation) incrementally after the UIKit text change delegate call returns, avoiding synchronous text and selection rewrites that can deadlock UIKeyboardTaskQueue.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<14682373d73e29327ec3c39882e59af5>>
* @generated SignedSource<<5fdbbc90102b64bf03e4a5f023da172d>>
*/

/**
Expand All @@ -23,6 +23,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var commonTestFlagCache: Boolean? = null
private var cdpInteractionMetricsEnabledCache: Boolean? = null
private var cxxNativeAnimatedEnabledCache: Boolean? = null
private var deferPreparedLayoutReactTagsToMountAndroidCache: Boolean? = null
private var deferTextInputTruncationIOSCache: Boolean? = null
private var disableEarlyViewCommandExecutionCache: Boolean? = null
private var disableIdleEventDispatchFrameCallbackRearmAndroidCache: Boolean? = null
Expand Down Expand Up @@ -150,6 +151,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun deferPreparedLayoutReactTagsToMountAndroid(): Boolean {
var cached = deferPreparedLayoutReactTagsToMountAndroidCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.deferPreparedLayoutReactTagsToMountAndroid()
deferPreparedLayoutReactTagsToMountAndroidCache = cached
}
return cached
}

override fun deferTextInputTruncationIOS(): Boolean {
var cached = deferTextInputTruncationIOSCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<bf090f6eea05b190d2f1ec51e5a0643a>>
* @generated SignedSource<<468d4d2268ca4d1049f6ac78440c250f>>
*/

/**
Expand Down Expand Up @@ -34,6 +34,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun cxxNativeAnimatedEnabled(): Boolean

@DoNotStrip @JvmStatic public external fun deferPreparedLayoutReactTagsToMountAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun deferTextInputTruncationIOS(): Boolean

@DoNotStrip @JvmStatic public external fun disableEarlyViewCommandExecution(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<d7d3d71a9022be2e753263699b3e2ec0>>
* @generated SignedSource<<aba57483a16f12555e1de38f3994395e>>
*/

/**
Expand All @@ -29,6 +29,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun cxxNativeAnimatedEnabled(): Boolean = true

override fun deferPreparedLayoutReactTagsToMountAndroid(): Boolean = false

override fun deferTextInputTruncationIOS(): Boolean = false

override fun disableEarlyViewCommandExecution(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<d09180773543b2c01eeeced9ec2205a7>>
* @generated SignedSource<<9eaf262ef1fbf2063256e05050b572a5>>
*/

/**
Expand All @@ -27,6 +27,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var commonTestFlagCache: Boolean? = null
private var cdpInteractionMetricsEnabledCache: Boolean? = null
private var cxxNativeAnimatedEnabledCache: Boolean? = null
private var deferPreparedLayoutReactTagsToMountAndroidCache: Boolean? = null
private var deferTextInputTruncationIOSCache: Boolean? = null
private var disableEarlyViewCommandExecutionCache: Boolean? = null
private var disableIdleEventDispatchFrameCallbackRearmAndroidCache: Boolean? = null
Expand Down Expand Up @@ -157,6 +158,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}

override fun deferPreparedLayoutReactTagsToMountAndroid(): Boolean {
var cached = deferPreparedLayoutReactTagsToMountAndroidCache
if (cached == null) {
cached = currentProvider.deferPreparedLayoutReactTagsToMountAndroid()
accessedFeatureFlags.add("deferPreparedLayoutReactTagsToMountAndroid")
deferPreparedLayoutReactTagsToMountAndroidCache = cached
}
return cached
}

override fun deferTextInputTruncationIOS(): Boolean {
var cached = deferTextInputTruncationIOSCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<bedaafe067d7c527f3c3d7b834f31888>>
* @generated SignedSource<<14de38050b966a9f50ce3db8445e9a8e>>
*/

/**
Expand All @@ -29,6 +29,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun cxxNativeAnimatedEnabled(): Boolean

@DoNotStrip public fun deferPreparedLayoutReactTagsToMountAndroid(): Boolean

@DoNotStrip public fun deferTextInputTruncationIOS(): Boolean

@DoNotStrip public fun disableEarlyViewCommandExecution(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,21 @@ internal class PreparedLayout(
// (truncated) text; every caller must consciously supply the complete string so accessibility
// and view-hierarchy consumers never fall back to the truncated text.
val sourceText: CharSequence,
)
) {
@DoNotStrip
fun withReactTags(reactTags: IntArray): PreparedLayout {
if (this.reactTags.contentEquals(reactTags)) {
return this
}
return PreparedLayout(
layout,
maximumNumberOfLines,
verticalOffset,
reactTags,
textBreakStrategy,
justificationMode,
baseTextAttributes,
sourceText,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<b6a5b98eda5fd2c8d06bc3812d85fd18>>
* @generated SignedSource<<bfbb516d17422a5fcec4eec5b8070b26>>
*/

/**
Expand Down Expand Up @@ -57,6 +57,12 @@ class ReactNativeFeatureFlagsJavaProvider
return method(javaProvider_);
}

bool deferPreparedLayoutReactTagsToMountAndroid() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("deferPreparedLayoutReactTagsToMountAndroid");
return method(javaProvider_);
}

bool deferTextInputTruncationIOS() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("deferTextInputTruncationIOS");
Expand Down Expand Up @@ -670,6 +676,11 @@ bool JReactNativeFeatureFlagsCxxInterop::cxxNativeAnimatedEnabled(
return ReactNativeFeatureFlags::cxxNativeAnimatedEnabled();
}

bool JReactNativeFeatureFlagsCxxInterop::deferPreparedLayoutReactTagsToMountAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::deferPreparedLayoutReactTagsToMountAndroid();
}

bool JReactNativeFeatureFlagsCxxInterop::deferTextInputTruncationIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::deferTextInputTruncationIOS();
Expand Down Expand Up @@ -1205,6 +1216,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"cxxNativeAnimatedEnabled",
JReactNativeFeatureFlagsCxxInterop::cxxNativeAnimatedEnabled),
makeNativeMethod(
"deferPreparedLayoutReactTagsToMountAndroid",
JReactNativeFeatureFlagsCxxInterop::deferPreparedLayoutReactTagsToMountAndroid),
makeNativeMethod(
"deferTextInputTruncationIOS",
JReactNativeFeatureFlagsCxxInterop::deferTextInputTruncationIOS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<61b3685bb0e41ac62de7cef4927b577c>>
* @generated SignedSource<<a49b001d559efc5c2b94f65926bf8586>>
*/

/**
Expand Down Expand Up @@ -39,6 +39,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool cxxNativeAnimatedEnabled(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool deferPreparedLayoutReactTagsToMountAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool deferTextInputTruncationIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) Meta Platforms, Inc. and 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.views.text

import android.annotation.SuppressLint
import android.graphics.text.LineBreakConfig
import android.text.Layout
import android.text.SpannableString
import android.text.TextPaint
import com.facebook.react.common.annotations.UnstableReactNativeAPI
import com.facebook.react.common.mapbuffer.WritableMapBuffer
import com.facebook.yoga.YogaMeasureMode
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode

@OptIn(UnstableReactNativeAPI::class)
@RunWith(RobolectricTestRunner::class)
@SuppressLint("NewApi")
@Config(sdk = [34])
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class PreparedLayoutTest {

private fun createPreparedLayout(reactTags: IntArray): PreparedLayout {
val text = SpannableString("Hello world")
val layout =
TextLayoutManager.createLayout(
text,
null,
200f,
YogaMeasureMode.AT_MOST,
true,
Layout.BREAK_STRATEGY_SIMPLE,
Layout.HYPHENATION_FREQUENCY_NONE,
LineBreakConfig.LINE_BREAK_STYLE_NONE,
LineBreakConfig.LINE_BREAK_WORD_STYLE_NONE,
Layout.Alignment.ALIGN_NORMAL,
Layout.JUSTIFICATION_MODE_NONE,
null,
-1,
TextPaint().apply { textSize = 14f },
)
return PreparedLayout(
layout = layout,
maximumNumberOfLines = 2,
verticalOffset = 1.5f,
reactTags = reactTags,
textBreakStrategy = Layout.BREAK_STRATEGY_SIMPLE,
justificationMode = Layout.JUSTIFICATION_MODE_NONE,
baseTextAttributes = TextAttributeProps.fromMapBuffer(WritableMapBuffer()),
sourceText = text,
)
}

@Test
fun `withReactTags returns same instance when tags match`() {
val original = createPreparedLayout(intArrayOf(10, 20))

val reused = original.withReactTags(intArrayOf(10, 20))

assertThat(reused).isSameAs(original)
}

@Test
fun `withReactTags clones wrapper sharing layout when tags differ`() {
val original = createPreparedLayout(intArrayOf(10, 20))

val reused = original.withReactTags(intArrayOf(30, 40))

assertThat(reused).isNotSameAs(original)
assertThat(reused.layout).isSameAs(original.layout)
assertThat(reused.sourceText).isSameAs(original.sourceText)
assertThat(reused.baseTextAttributes).isSameAs(original.baseTextAttributes)
assertThat(reused.maximumNumberOfLines).isEqualTo(original.maximumNumberOfLines)
assertThat(reused.verticalOffset).isEqualTo(original.verticalOffset)
assertThat(reused.textBreakStrategy).isEqualTo(original.textBreakStrategy)
assertThat(reused.justificationMode).isEqualTo(original.justificationMode)
assertThat(reused.reactTags).containsExactly(30, 40)
assertThat(original.reactTags).containsExactly(10, 20)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<81cd9f64e05f8e5d59eb79c0ecfeda86>>
* @generated SignedSource<<470484ff52dc6b23e70be65aef8e3c59>>
*/

/**
Expand Down Expand Up @@ -38,6 +38,10 @@ bool ReactNativeFeatureFlags::cxxNativeAnimatedEnabled() {
return getAccessor().cxxNativeAnimatedEnabled();
}

bool ReactNativeFeatureFlags::deferPreparedLayoutReactTagsToMountAndroid() {
return getAccessor().deferPreparedLayoutReactTagsToMountAndroid();
}

bool ReactNativeFeatureFlags::deferTextInputTruncationIOS() {
return getAccessor().deferTextInputTruncationIOS();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<8dca25c44632b8b14c5cdac75a3f36f8>>
* @generated SignedSource<<c62cdc6f58fda49d906ac8b654ba22ac>>
*/

/**
Expand Down Expand Up @@ -56,6 +56,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool cxxNativeAnimatedEnabled();

/**
* When enabled, cached PreparedLayout objects are shared across ParagraphShadowNodes without creating new JNI global references for differing React tags; new React tags are attached via a local JNI reference on mount.
*/
RN_EXPORT static bool deferPreparedLayoutReactTagsToMountAndroid();

/**
* When enabled, iOS TextInput applies edits that JS transforms (e.g. maxLength truncation) incrementally after the UIKit text change delegate call returns, avoiding synchronous text and selection rewrites that can deadlock UIKeyboardTaskQueue.
*/
Expand Down
Loading
Loading