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
15 changes: 15 additions & 0 deletions packages/react-native/Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import type {GestureResponderEvent} from '../Types/CoreEventTypes';
import type {NativeTextProps} from './TextNativeComponent';
import type {PressRetentionOffset, TextProps} from './TextProps';

import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags';
import * as PressabilityDebug from '../Pressability/PressabilityDebug';
import usePressability from '../Pressability/usePressability';
import flattenStyle from '../StyleSheet/flattenStyle';
import processColor from '../StyleSheet/processColor';
import StyleSheet from '../StyleSheet/StyleSheet';
import Platform from '../Utilities/Platform';
import TextAncestorContext from './TextAncestorContext';
import {NativeText, NativeVirtualText} from './TextNativeComponent';
Expand Down Expand Up @@ -209,6 +211,10 @@ const TextImpl: component(
}
}

if (ReactNativeFeatureFlags.defaultTextToOverflowHidden()) {
_style = [styles.default, _style];
}

const _nativeID = id ?? nativeID;

if (_accessibilityLabel !== undefined) {
Expand Down Expand Up @@ -541,4 +547,13 @@ const verticalAlignToTextAlignVerticalMap = {
middle: 'center',
} as const;

const styles = StyleSheet.create({
// Native components have historically acted like overflow: 'hidden'. We set
// this, as part of the default style, to let client differentiate with
// overflow: 'visible'.
default: {
overflow: 'hidden',
},
});

export default TextImpl;
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<<67ef2bd30983c949f41e014297dabd6e>>
* @generated SignedSource<<d0b64e027b64f0d2cf4dd08cf875498d>>
*/

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

/**
* When enabled, sets the default overflow style for Text components to hidden instead of visible.
*/
@JvmStatic
public fun defaultTextToOverflowHidden(): Boolean = accessor.defaultTextToOverflowHidden()

/**
* Dispatch view commands in mount item order.
*/
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<<e3373e6363e3d9c35102fcff311570b1>>
* @generated SignedSource<<87cf87f7ee1e30851c653a23769e46d4>>
*/

/**
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 defaultTextToOverflowHiddenCache: Boolean? = null
private var disableEarlyViewCommandExecutionCache: Boolean? = null
private var disableImageViewPreallocationAndroidCache: Boolean? = null
private var disableMountItemReorderingAndroidCache: Boolean? = null
Expand Down Expand Up @@ -128,6 +129,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}

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

override fun disableEarlyViewCommandExecution(): Boolean {
var cached = disableEarlyViewCommandExecutionCache
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<<ca705ae15584cb6bc81c4b1097adb09a>>
* @generated SignedSource<<a1ec288099292f7498ddca428cd73e7e>>
*/

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

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

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

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

@DoNotStrip @JvmStatic public external fun disableImageViewPreallocationAndroid(): 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<<62ddb63e95e2b2aff842c5d13210d742>>
* @generated SignedSource<<b1dd00ce64e33e4e816f1e32e0b7b42e>>
*/

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

override fun cxxNativeAnimatedEnabled(): Boolean = false

override fun defaultTextToOverflowHidden(): Boolean = false

override fun disableEarlyViewCommandExecution(): Boolean = false

override fun disableImageViewPreallocationAndroid(): 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<<477ec1cf98790b5219ed37092ae958cc>>
* @generated SignedSource<<0557ebe38faff44400e5acb150587c78>>
*/

/**
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 defaultTextToOverflowHiddenCache: Boolean? = null
private var disableEarlyViewCommandExecutionCache: Boolean? = null
private var disableImageViewPreallocationAndroidCache: Boolean? = null
private var disableMountItemReorderingAndroidCache: Boolean? = null
Expand Down Expand Up @@ -135,6 +136,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}

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

override fun disableEarlyViewCommandExecution(): Boolean {
var cached = disableEarlyViewCommandExecutionCache
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<<4480d856ab56f2ecb216610b6e4ae31e>>
* @generated SignedSource<<b509f563ea4f3f072c2fc309462f8778>>
*/

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

@DoNotStrip public fun cxxNativeAnimatedEnabled(): Boolean

@DoNotStrip public fun defaultTextToOverflowHidden(): Boolean

@DoNotStrip public fun disableEarlyViewCommandExecution(): Boolean

@DoNotStrip public fun disableImageViewPreallocationAndroid(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ internal class PreparedLayoutTextView(context: Context) : ViewGroup(context), Re
}
}

// T221698007: This is closest to existing behavior, but does not align with web. We may want to
// change in the future if not too breaking.
var overflow: Overflow = Overflow.HIDDEN
var overflow: Overflow = Overflow.VISIBLE
set(value) {
if (field != value) {
field = value
Expand Down Expand Up @@ -99,7 +97,7 @@ internal class PreparedLayoutTextView(context: Context) : ViewGroup(context), Re
fun recycleView(): Unit {
initView()
BackgroundStyleApplicator.reset(this)
overflow = Overflow.HIDDEN
overflow = Overflow.VISIBLE
}

override fun onDraw(canvas: Canvas) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ internal class PreparedLayoutTextViewManager :

@ReactProp(name = "overflow")
fun setOverflow(view: PreparedLayoutTextView, overflow: String?): Unit {
view.overflow = overflow?.let { Overflow.fromString(it) } ?: Overflow.HIDDEN
view.overflow = overflow?.let { Overflow.fromString(it) } ?: Overflow.VISIBLE
}

@ReactProp(name = "accessible")
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<<176845e66b87994db4a9199df21740c0>>
* @generated SignedSource<<22918d9ec9eefdeeefd733ebe767d18a>>
*/

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

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

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

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

bool JReactNativeFeatureFlagsCxxInterop::disableEarlyViewCommandExecution(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::disableEarlyViewCommandExecution();
Expand Down Expand Up @@ -963,6 +974,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"cxxNativeAnimatedEnabled",
JReactNativeFeatureFlagsCxxInterop::cxxNativeAnimatedEnabled),
makeNativeMethod(
"defaultTextToOverflowHidden",
JReactNativeFeatureFlagsCxxInterop::defaultTextToOverflowHidden),
makeNativeMethod(
"disableEarlyViewCommandExecution",
JReactNativeFeatureFlagsCxxInterop::disableEarlyViewCommandExecution),
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<<4078cafe7570b1478adc0b278a25155a>>
* @generated SignedSource<<0175d2600dacd7c7eb9c17fc9fcc36c4>>
*/

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

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

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

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<<e0f2fdab52f83a4bf8156bc4e55e0760>>
* @generated SignedSource<<68a5ea400cfa90c6504360b6fae52932>>
*/

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

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

bool ReactNativeFeatureFlags::disableEarlyViewCommandExecution() {
return getAccessor().disableEarlyViewCommandExecution();
}
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<<c24c659a80be5371844c214a69c149bd>>
* @generated SignedSource<<9df77f1103d4aa3bf96bb7cad32ad230>>
*/

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

/**
* When enabled, sets the default overflow style for Text components to hidden instead of visible.
*/
RN_EXPORT static bool defaultTextToOverflowHidden();

/**
* Dispatch view commands in mount item order.
*/
Expand Down
Loading
Loading