mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Revert D92928315: Initial support for selectable text with enablePreparedTextLayout
Differential Revision: D92928315 Original commit changeset: 863988167692 Original Phabricator Diff: D92928315 fbshipit-source-id: e5f7254243845c027fc8d77f5e99cb8aded837e7
This commit is contained in:
1 parent
16d4bd1710
commit
3296af74e1
17 files changed
+87
-252
No files matched your search
+36
-33
@@ -20,18 +20,14 @@ import flattenStyle from '../StyleSheet/flattenStyle';
|
||||
import processColor from '../StyleSheet/processColor';
|
||||
import Platform from '../Utilities/Platform';
|
||||
import TextAncestorContext from './TextAncestorContext';
|
||||
import {
|
||||
NativeSelectableText,
|
||||
NativeText,
|
||||
NativeVirtualText,
|
||||
} from './TextNativeComponent';
|
||||
import {NativeText, NativeVirtualText} from './TextNativeComponent';
|
||||
import * as React from 'react';
|
||||
import {useContext, useMemo, useState} from 'react';
|
||||
|
||||
export type {TextProps} from './TextProps';
|
||||
|
||||
type TextForwardRef = React.ElementRef<
|
||||
typeof NativeText | typeof NativeVirtualText | typeof NativeSelectableText,
|
||||
typeof NativeText | typeof NativeVirtualText,
|
||||
>;
|
||||
|
||||
/**
|
||||
@@ -267,7 +263,7 @@ const TextImpl: component(
|
||||
processedProps.children = children;
|
||||
if (isPressable) {
|
||||
return (
|
||||
<PressableVirtualText
|
||||
<NativePressableVirtualText
|
||||
ref={forwardedRef}
|
||||
textProps={processedProps}
|
||||
textPressabilityProps={textPressabilityProps ?? {}}
|
||||
@@ -287,20 +283,14 @@ const TextImpl: component(
|
||||
|
||||
if (isPressable) {
|
||||
nativeText = (
|
||||
<PressableText
|
||||
<NativePressableText
|
||||
ref={forwardedRef}
|
||||
selectable={_selectable}
|
||||
textProps={processedProps}
|
||||
textPressabilityProps={textPressabilityProps ?? {}}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
nativeText =
|
||||
_selectable === true ? (
|
||||
<NativeSelectableText {...processedProps} ref={forwardedRef} />
|
||||
) : (
|
||||
<NativeText {...processedProps} ref={forwardedRef} />
|
||||
);
|
||||
nativeText = <NativeText {...processedProps} ref={forwardedRef} />;
|
||||
}
|
||||
|
||||
if (children == null) {
|
||||
@@ -467,17 +457,28 @@ function useTextPressability({
|
||||
);
|
||||
}
|
||||
|
||||
type NativePressableTextProps = Readonly<{
|
||||
textProps: NativeTextProps,
|
||||
textPressabilityProps: TextPressabilityProps,
|
||||
}>;
|
||||
|
||||
/**
|
||||
* Wrap the NativeVirtualText component and initialize pressability.
|
||||
*
|
||||
* This logic is split out from the main Text component to enable the more
|
||||
* expensive pressability logic to be only initialized when needed.
|
||||
*/
|
||||
component PressableVirtualText(
|
||||
const NativePressableVirtualText: component(
|
||||
ref: React.RefSetter<TextForwardRef>,
|
||||
...props: NativePressableTextProps
|
||||
) = ({
|
||||
ref: forwardedRef,
|
||||
textProps,
|
||||
textPressabilityProps,
|
||||
}: {
|
||||
ref?: React.RefSetter<TextForwardRef>,
|
||||
textProps: NativeTextProps,
|
||||
textPressabilityProps: TextPressabilityProps,
|
||||
) {
|
||||
...NativePressableTextProps,
|
||||
}) => {
|
||||
const [isHighlighted, eventHandlersForText] = useTextPressability(
|
||||
textPressabilityProps,
|
||||
);
|
||||
@@ -488,40 +489,42 @@ component PressableVirtualText(
|
||||
{...eventHandlersForText}
|
||||
isHighlighted={isHighlighted}
|
||||
isPressable={true}
|
||||
ref={ref}
|
||||
ref={forwardedRef}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrap a NativeText component and initialize pressability.
|
||||
* Wrap the NativeText component and initialize pressability.
|
||||
*
|
||||
* This logic is split out from the main Text component to enable the more
|
||||
* expensive pressability logic to be only initialized when needed.
|
||||
*/
|
||||
component PressableText(
|
||||
const NativePressableText: component(
|
||||
ref: React.RefSetter<TextForwardRef>,
|
||||
...props: NativePressableTextProps
|
||||
) = ({
|
||||
ref: forwardedRef,
|
||||
textProps,
|
||||
textPressabilityProps,
|
||||
}: {
|
||||
ref?: React.RefSetter<TextForwardRef>,
|
||||
selectable?: ?boolean,
|
||||
textProps: NativeTextProps,
|
||||
textPressabilityProps: TextPressabilityProps,
|
||||
) {
|
||||
...NativePressableTextProps,
|
||||
}) => {
|
||||
const [isHighlighted, eventHandlersForText] = useTextPressability(
|
||||
textPressabilityProps,
|
||||
);
|
||||
|
||||
const NativeComponent =
|
||||
selectable === true ? NativeSelectableText : NativeText;
|
||||
|
||||
return (
|
||||
<NativeComponent
|
||||
<NativeText
|
||||
{...textProps}
|
||||
{...eventHandlersForText}
|
||||
isHighlighted={isHighlighted}
|
||||
isPressable={true}
|
||||
ref={ref}
|
||||
ref={forwardedRef}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const userSelectToSelectableMap = {
|
||||
auto: true,
|
||||
|
||||
@@ -13,7 +13,6 @@ import type {ProcessedColorValue} from '../StyleSheet/processColor';
|
||||
import type {GestureResponderEvent} from '../Types/CoreEventTypes';
|
||||
import type {TextProps} from './TextProps';
|
||||
|
||||
import {enablePreparedTextLayout} from '../../src/private/featureflags/ReactNativeFeatureFlags';
|
||||
import {createViewConfig} from '../NativeComponent/ViewConfig';
|
||||
import UIManager from '../ReactNative/UIManager';
|
||||
import createReactNativeComponentClass from '../Renderer/shims/createReactNativeComponentClass';
|
||||
@@ -91,15 +90,3 @@ export const NativeVirtualText: HostComponent<NativeTextProps> =
|
||||
* https://fburl.com/workplace/6291gfvu */
|
||||
createViewConfig(virtualTextViewConfig),
|
||||
): any);
|
||||
|
||||
export const NativeSelectableText: HostComponent<NativeTextProps> =
|
||||
enablePreparedTextLayout()
|
||||
? (createReactNativeComponentClass('RCTSelectableText', () =>
|
||||
/* $FlowFixMe[incompatible-type] Natural Inference rollout. See
|
||||
* https://fburl.com/workplace/6291gfvu */
|
||||
createViewConfig({
|
||||
...textViewConfig,
|
||||
uiViewClassName: 'RCTSelectableText',
|
||||
}),
|
||||
): any)
|
||||
: NativeText;
|
||||
@@ -6114,7 +6114,7 @@ public class com/facebook/react/views/text/ReactTextView : androidx/appcompat/wi
|
||||
public fun updateView ()V
|
||||
}
|
||||
|
||||
public class com/facebook/react/views/text/ReactTextViewManager : com/facebook/react/uimanager/BaseViewManager, com/facebook/react/uimanager/IViewManagerWithChildren, com/facebook/react/views/text/ReactTextViewManagerCallback {
|
||||
public final class com/facebook/react/views/text/ReactTextViewManager : com/facebook/react/uimanager/BaseViewManager, com/facebook/react/uimanager/IViewManagerWithChildren, com/facebook/react/views/text/ReactTextViewManagerCallback {
|
||||
public static final field Companion Lcom/facebook/react/views/text/ReactTextViewManager$Companion;
|
||||
public static final field REACT_CLASS Ljava/lang/String;
|
||||
public fun <init> ()V
|
||||
@@ -6127,14 +6127,11 @@ public class com/facebook/react/views/text/ReactTextViewManager : com/facebook/r
|
||||
public fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Lcom/facebook/react/views/text/ReactTextView;
|
||||
public fun getExportedCustomDirectEventTypeConstants ()Ljava/util/Map;
|
||||
public fun getName ()Ljava/lang/String;
|
||||
protected final fun getReactTextViewManagerCallback ()Lcom/facebook/react/views/text/ReactTextViewManagerCallback;
|
||||
public fun getShadowNodeClass ()Ljava/lang/Class;
|
||||
public fun needsCustomLayoutForChildren ()Z
|
||||
public synthetic fun onAfterUpdateTransaction (Landroid/view/View;)V
|
||||
protected fun onAfterUpdateTransaction (Lcom/facebook/react/views/text/ReactTextView;)V
|
||||
public fun onPostProcessSpannable (Landroid/text/Spannable;)V
|
||||
public synthetic fun prepareToRecycleView (Lcom/facebook/react/uimanager/ThemedReactContext;Landroid/view/View;)Landroid/view/View;
|
||||
protected fun prepareToRecycleView (Lcom/facebook/react/uimanager/ThemedReactContext;Lcom/facebook/react/views/text/ReactTextView;)Lcom/facebook/react/views/text/ReactTextView;
|
||||
public final fun setAccessible (Lcom/facebook/react/views/text/ReactTextView;Z)V
|
||||
public final fun setAdjustFontSizeToFit (Lcom/facebook/react/views/text/ReactTextView;Z)V
|
||||
public final fun setAndroidHyphenationFrequency (Lcom/facebook/react/views/text/ReactTextView;Ljava/lang/String;)V
|
||||
@@ -6152,7 +6149,6 @@ public class com/facebook/react/views/text/ReactTextViewManager : com/facebook/r
|
||||
public final fun setOverflow (Lcom/facebook/react/views/text/ReactTextView;Ljava/lang/String;)V
|
||||
public synthetic fun setPadding (Landroid/view/View;IIII)V
|
||||
public fun setPadding (Lcom/facebook/react/views/text/ReactTextView;IIII)V
|
||||
protected final fun setReactTextViewManagerCallback (Lcom/facebook/react/views/text/ReactTextViewManagerCallback;)V
|
||||
public final fun setSelectable (Lcom/facebook/react/views/text/ReactTextView;Z)V
|
||||
public final fun setSelectionColor (Lcom/facebook/react/views/text/ReactTextView;Ljava/lang/Integer;)V
|
||||
public final fun setTextAlignVertical (Lcom/facebook/react/views/text/ReactTextView;Ljava/lang/String;)V
|
||||
@@ -6161,7 +6157,6 @@ public class com/facebook/react/views/text/ReactTextViewManager : com/facebook/r
|
||||
public synthetic fun updateState (Landroid/view/View;Lcom/facebook/react/uimanager/ReactStylesDiffMap;Lcom/facebook/react/uimanager/StateWrapper;)Ljava/lang/Object;
|
||||
public fun updateState (Lcom/facebook/react/views/text/ReactTextView;Lcom/facebook/react/uimanager/ReactStylesDiffMap;Lcom/facebook/react/uimanager/StateWrapper;)Ljava/lang/Object;
|
||||
public synthetic fun updateViewAccessibility (Landroid/view/View;)V
|
||||
protected fun updateViewAccessibility (Lcom/facebook/react/views/text/ReactTextView;)V
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/text/ReactTextViewManager$Companion {
|
||||
@@ -6179,9 +6174,6 @@ public final class com/facebook/react/views/text/ReactTypefaceUtils {
|
||||
public static final fun parseFontWeight (Ljava/lang/String;)I
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/text/SelectableTextViewManager$Companion {
|
||||
}
|
||||
|
||||
public final class com/facebook/react/views/text/TextAttributeProps {
|
||||
public static final field Companion Lcom/facebook/react/views/text/TextAttributeProps$Companion;
|
||||
public static final field TA_KEY_ACCESSIBILITY_ROLE I
|
||||
|
||||
-1
@@ -18,7 +18,6 @@ internal object FabricNameComponentMapping {
|
||||
"Slider" to "RCTSlider",
|
||||
"ModalHostView" to "RCTModalHostView",
|
||||
"Paragraph" to "RCTText",
|
||||
"SelectableParagraph" to "RCTSelectableText",
|
||||
"Text" to "RCTText",
|
||||
"RawText" to "RCTRawText",
|
||||
"ActivityIndicatorView" to "AndroidProgressBar",
|
||||
|
||||
-6
@@ -15,7 +15,6 @@ import com.facebook.react.bridge.ModuleSpec
|
||||
import com.facebook.react.bridge.NativeModule
|
||||
import com.facebook.react.bridge.ReactApplicationContext
|
||||
import com.facebook.react.common.ClassFinder
|
||||
import com.facebook.react.common.annotations.UnstableReactNativeAPI
|
||||
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
|
||||
import com.facebook.react.module.annotations.ReactModule
|
||||
import com.facebook.react.module.annotations.ReactModuleList
|
||||
@@ -59,7 +58,6 @@ import com.facebook.react.views.swiperefresh.SwipeRefreshLayoutManager
|
||||
import com.facebook.react.views.switchview.ReactSwitchManager
|
||||
import com.facebook.react.views.text.PreparedLayoutTextViewManager
|
||||
import com.facebook.react.views.text.ReactTextViewManager
|
||||
import com.facebook.react.views.text.SelectableTextViewManager
|
||||
import com.facebook.react.views.textinput.ReactTextInputManager
|
||||
import com.facebook.react.views.unimplementedview.ReactUnimplementedViewManager
|
||||
import com.facebook.react.views.view.ReactViewManager
|
||||
@@ -98,7 +96,6 @@ import com.facebook.react.views.view.ReactViewManager
|
||||
WebSocketModule::class,
|
||||
]
|
||||
)
|
||||
@OptIn(UnstableReactNativeAPI::class)
|
||||
public class MainReactPackage
|
||||
@JvmOverloads
|
||||
constructor(private val config: MainPackageConfig? = null) :
|
||||
@@ -153,7 +150,6 @@ constructor(private val config: MainPackageConfig? = null) :
|
||||
ReactTextInputManager(),
|
||||
if (ReactNativeFeatureFlags.enablePreparedTextLayout()) PreparedLayoutTextViewManager()
|
||||
else ReactTextViewManager(),
|
||||
SelectableTextViewManager(),
|
||||
ReactViewManager(),
|
||||
ReactUnimplementedViewManager(),
|
||||
)
|
||||
@@ -196,8 +192,6 @@ constructor(private val config: MainPackageConfig? = null) :
|
||||
PreparedLayoutTextViewManager()
|
||||
else ReactTextViewManager()
|
||||
},
|
||||
SelectableTextViewManager.REACT_CLASS to
|
||||
ModuleSpec.viewManagerSpec { SelectableTextViewManager() },
|
||||
ReactViewManager.REACT_CLASS to ModuleSpec.viewManagerSpec { ReactViewManager() },
|
||||
ReactUnimplementedViewManager.REACT_CLASS to
|
||||
ModuleSpec.viewManagerSpec { ReactUnimplementedViewManager() },
|
||||
|
||||
+2
-3
@@ -118,9 +118,8 @@ internal class PreparedLayoutTextViewManager :
|
||||
|
||||
@ReactProp(name = "selectable", defaultBoolean = false)
|
||||
fun setSelectable(view: PreparedLayoutTextView, isSelectable: Boolean): Unit {
|
||||
check(!isSelectable) {
|
||||
"selectable Text should use SelectableTextViewManager instead of PreparedLayoutViewManager"
|
||||
}
|
||||
// T222052152: Implement fine-grained text selection for PreparedLayoutTextView
|
||||
// view.setTextIsSelectable(isSelectable);
|
||||
}
|
||||
|
||||
@ReactProp(name = "selectionColor", customType = "Color")
|
||||
|
||||
+1
-36
@@ -12,7 +12,6 @@ package com.facebook.react.views.text
|
||||
import android.os.Build
|
||||
import android.text.Layout
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.Spanned
|
||||
import android.text.TextUtils
|
||||
import android.text.util.Linkify
|
||||
@@ -32,7 +31,6 @@ import com.facebook.react.uimanager.LayoutShadowNode
|
||||
import com.facebook.react.uimanager.LengthPercentage
|
||||
import com.facebook.react.uimanager.LengthPercentageType
|
||||
import com.facebook.react.uimanager.ReactStylesDiffMap
|
||||
import com.facebook.react.uimanager.ReferenceStateWrapper
|
||||
import com.facebook.react.uimanager.StateWrapper
|
||||
import com.facebook.react.uimanager.ThemedReactContext
|
||||
import com.facebook.react.uimanager.ViewDefaults
|
||||
@@ -48,7 +46,7 @@ import java.util.HashMap
|
||||
/** View manager for `<Text>` nodes. */
|
||||
@ReactModule(name = ReactTextViewManager.REACT_CLASS)
|
||||
@OptIn(UnstableReactNativeAPI::class)
|
||||
public open class ReactTextViewManager
|
||||
public class ReactTextViewManager
|
||||
@JvmOverloads
|
||||
public constructor(
|
||||
protected var reactTextViewManagerCallback: ReactTextViewManagerCallback? = null
|
||||
@@ -133,11 +131,6 @@ public constructor(
|
||||
stateWrapper: StateWrapper,
|
||||
): Any? {
|
||||
SystraceSection("ReactTextViewManager.updateState").use { s ->
|
||||
val refState = (stateWrapper as? ReferenceStateWrapper)?.stateDataReference
|
||||
if (refState is PreparedLayout) {
|
||||
return getReactTextUpdateFromPreparedLayout(view, refState)
|
||||
}
|
||||
|
||||
val stateMapBuffer = stateWrapper.stateDataMapBuffer
|
||||
return if (stateMapBuffer != null) {
|
||||
getReactTextUpdate(view, props, stateMapBuffer)
|
||||
@@ -183,34 +176,6 @@ public constructor(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a [ReactTextUpdate] from a [PreparedLayout] received via [ReferenceStateWrapper].
|
||||
*/
|
||||
private fun getReactTextUpdateFromPreparedLayout(
|
||||
view: ReactTextView,
|
||||
preparedLayout: PreparedLayout,
|
||||
): ReactTextUpdate {
|
||||
val layout = preparedLayout.layout
|
||||
val text = layout.text
|
||||
val spanned = if (text is Spannable) text else SpannableString(text)
|
||||
view.setSpanned(spanned)
|
||||
|
||||
val textAlign =
|
||||
when (layout.alignment) {
|
||||
Layout.Alignment.ALIGN_CENTER -> Gravity.CENTER_HORIZONTAL
|
||||
Layout.Alignment.ALIGN_OPPOSITE -> Gravity.END
|
||||
else -> Gravity.START
|
||||
}
|
||||
|
||||
return ReactTextUpdate(
|
||||
spanned,
|
||||
-1,
|
||||
textAlign,
|
||||
Layout.BREAK_STRATEGY_HIGH_QUALITY,
|
||||
0,
|
||||
)
|
||||
}
|
||||
|
||||
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? {
|
||||
val baseEventTypeConstants = super.getExportedCustomDirectEventTypeConstants()
|
||||
val eventTypeConstants = baseEventTypeConstants ?: HashMap()
|
||||
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* 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 com.facebook.react.common.annotations.UnstableReactNativeAPI
|
||||
|
||||
/**
|
||||
* A [ReactTextViewManager] registered under the name "RCTSelectableText". Used to route selectable
|
||||
* text through [ReactTextView] (a real [android.widget.TextView]) instead of
|
||||
* [PreparedLayoutTextView] when enablePreparedTextLayout is on, since [PreparedLayoutTextView] does
|
||||
* not support native text selection.
|
||||
*/
|
||||
@UnstableReactNativeAPI
|
||||
public class SelectableTextViewManager
|
||||
@JvmOverloads
|
||||
public constructor(reactTextViewManagerCallback: ReactTextViewManagerCallback? = null) :
|
||||
ReactTextViewManager(reactTextViewManagerCallback) {
|
||||
|
||||
override fun getName(): String = REACT_CLASS
|
||||
|
||||
public companion object {
|
||||
public const val REACT_CLASS: String = "RCTSelectableText"
|
||||
}
|
||||
}
|
||||
-4
@@ -21,7 +21,6 @@
|
||||
#include <react/renderer/components/scrollview/ScrollViewComponentDescriptor.h>
|
||||
#include <react/renderer/components/text/ParagraphComponentDescriptor.h>
|
||||
#include <react/renderer/components/text/RawTextComponentDescriptor.h>
|
||||
#include <react/renderer/components/text/SelectableParagraphComponentDescriptor.h>
|
||||
#include <react/renderer/components/text/TextComponentDescriptor.h>
|
||||
#include <react/renderer/components/view/LayoutConformanceComponentDescriptor.h>
|
||||
#include <react/renderer/components/view/ViewComponentDescriptor.h>
|
||||
@@ -72,9 +71,6 @@ void addCoreComponents(
|
||||
AndroidHorizontalScrollContentViewComponentDescriptor>());
|
||||
providerRegistry->add(
|
||||
concreteComponentDescriptorProvider<ParagraphComponentDescriptor>());
|
||||
providerRegistry->add(
|
||||
concreteComponentDescriptorProvider<
|
||||
SelectableParagraphComponentDescriptor>());
|
||||
providerRegistry->add(
|
||||
concreteComponentDescriptorProvider<
|
||||
AndroidDrawerLayoutComponentDescriptor>());
|
||||
|
||||
-3
@@ -27,9 +27,6 @@ std::string componentNameByReactViewName(std::string viewName) {
|
||||
if (viewName == "Text") {
|
||||
return "Paragraph";
|
||||
}
|
||||
if (viewName == "SelectableText") {
|
||||
return "SelectableParagraph";
|
||||
}
|
||||
|
||||
if (viewName == "VirtualText") {
|
||||
return "Text";
|
||||
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
||||
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
|
||||
#include <react/utils/ContextContainer.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
constexpr const char *const TextLayoutManagerKey = "TextLayoutManager";
|
||||
|
||||
template <typename ShadowNodeT>
|
||||
class BaseParagraphComponentDescriptor : public ConcreteComponentDescriptor<ShadowNodeT> {
|
||||
public:
|
||||
explicit BaseParagraphComponentDescriptor(const ComponentDescriptorParameters ¶meters)
|
||||
: ConcreteComponentDescriptor<ShadowNodeT>(parameters),
|
||||
textLayoutManager_(getManagerByName<TextLayoutManager>(this->contextContainer_, TextLayoutManagerKey))
|
||||
{
|
||||
}
|
||||
|
||||
ComponentName getComponentName() const override
|
||||
{
|
||||
return ShadowNodeT::Name();
|
||||
}
|
||||
|
||||
protected:
|
||||
void adopt(ShadowNode &shadowNode) const override
|
||||
{
|
||||
ConcreteComponentDescriptor<ShadowNodeT>::adopt(shadowNode);
|
||||
|
||||
auto ¶graphShadowNode = static_cast<ShadowNodeT &>(shadowNode);
|
||||
|
||||
// `ParagraphShadowNode` uses `TextLayoutManager` to measure text content
|
||||
// and communicate text rendering metrics to mounting layer.
|
||||
paragraphShadowNode.setTextLayoutManager(textLayoutManager_);
|
||||
}
|
||||
|
||||
private:
|
||||
// Every `ParagraphShadowNode` has a reference to a shared `TextLayoutManager`
|
||||
const std::shared_ptr<const TextLayoutManager> textLayoutManager_;
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ParagraphComponentDescriptor.h"
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
extern const char TextLayoutManagerKey[] = "TextLayoutManager";
|
||||
|
||||
} // namespace facebook::react
|
||||
+28
-3
@@ -7,16 +7,41 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/components/text/BaseParagraphComponentDescriptor.h>
|
||||
#include <react/renderer/components/text/ParagraphShadowNode.h>
|
||||
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
||||
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
|
||||
#include <react/utils/ContextContainer.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
extern const char TextLayoutManagerKey[];
|
||||
|
||||
/*
|
||||
* Descriptor for <Paragraph> component.
|
||||
*/
|
||||
class ParagraphComponentDescriptor final : public BaseParagraphComponentDescriptor<ParagraphShadowNode> {
|
||||
class ParagraphComponentDescriptor final : public ConcreteComponentDescriptor<ParagraphShadowNode> {
|
||||
public:
|
||||
using BaseParagraphComponentDescriptor::BaseParagraphComponentDescriptor;
|
||||
explicit ParagraphComponentDescriptor(const ComponentDescriptorParameters ¶meters)
|
||||
: ConcreteComponentDescriptor<ParagraphShadowNode>(parameters),
|
||||
textLayoutManager_(getManagerByName<TextLayoutManager>(contextContainer_, TextLayoutManagerKey))
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void adopt(ShadowNode &shadowNode) const override
|
||||
{
|
||||
ConcreteComponentDescriptor::adopt(shadowNode);
|
||||
|
||||
auto ¶graphShadowNode = static_cast<ParagraphShadowNode &>(shadowNode);
|
||||
|
||||
// `ParagraphShadowNode` uses `TextLayoutManager` to measure text content
|
||||
// and communicate text rendering metrics to mounting layer.
|
||||
paragraphShadowNode.setTextLayoutManager(textLayoutManager_);
|
||||
}
|
||||
|
||||
private:
|
||||
// Every `ParagraphShadowNode` has a reference to a shared `TextLayoutManager`
|
||||
const std::shared_ptr<const TextLayoutManager> textLayoutManager_;
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
+1
-1
@@ -26,7 +26,7 @@ extern const char ParagraphComponentName[];
|
||||
* containing and displaying text. Text content is represented as nested <Text>
|
||||
* and <RawText> components.
|
||||
*/
|
||||
class ParagraphShadowNode
|
||||
class ParagraphShadowNode final
|
||||
: public ConcreteViewShadowNode<ParagraphComponentName, ParagraphProps, ParagraphEventEmitter, ParagraphState>,
|
||||
public BaseTextShadowNode {
|
||||
public:
|
||||
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/components/text/BaseParagraphComponentDescriptor.h>
|
||||
#include <react/renderer/components/text/SelectableParagraphShadowNode.h>
|
||||
|
||||
namespace facebook::react {
|
||||
/*
|
||||
* Descriptor for <SelectableParagraph> component, which may render to a
|
||||
* different native view than <Paragraph>.
|
||||
*/
|
||||
class SelectableParagraphComponentDescriptor final
|
||||
: public BaseParagraphComponentDescriptor<SelectableParagraphShadowNode> {
|
||||
public:
|
||||
using BaseParagraphComponentDescriptor::BaseParagraphComponentDescriptor;
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/components/text/ParagraphShadowNode.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
/*
|
||||
* ShadowNode for selectable Paragraph components, which may map to different native component than Paragraph.
|
||||
*/
|
||||
class SelectableParagraphShadowNode : public ParagraphShadowNode {
|
||||
public:
|
||||
using ParagraphShadowNode::ParagraphShadowNode;
|
||||
|
||||
static constexpr ComponentName Name()
|
||||
{
|
||||
return "SelectableParagraph";
|
||||
}
|
||||
|
||||
static ComponentHandle Handle()
|
||||
{
|
||||
return ComponentHandle(Name());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
+4
-6
@@ -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<<d41b8dabdc1efeb52004c2df5c93963c>>
|
||||
* @generated SignedSource<<6463b0a4f3acbeb07e6759c345b927d8>>
|
||||
*
|
||||
* This file was generated by scripts/js-api/build-types/index.js.
|
||||
*/
|
||||
@@ -322,7 +322,6 @@ declare const NativeModules: typeof NativeModules_default
|
||||
declare let NativeModules_default: {
|
||||
[moduleName: string]: any
|
||||
}
|
||||
declare const NativeSelectableText: HostComponent<NativeTextProps>
|
||||
declare const NativeText: HostComponent<NativeTextProps>
|
||||
declare const NativeTouchable:
|
||||
| typeof TouchableNativeFeedback
|
||||
@@ -3369,7 +3368,6 @@ declare type NativeScrollVelocity = {
|
||||
readonly x: number
|
||||
readonly y: number
|
||||
}
|
||||
declare type NativeSelectableText = typeof NativeSelectableText
|
||||
declare type NativeSwitchChangeEvent = {
|
||||
readonly target: Int32
|
||||
readonly value: boolean
|
||||
@@ -5162,7 +5160,7 @@ declare type TextContentType =
|
||||
| "URL"
|
||||
| "username"
|
||||
declare type TextForwardRef = React.ComponentRef<
|
||||
typeof NativeSelectableText | typeof NativeText | typeof NativeVirtualText
|
||||
typeof NativeText | typeof NativeVirtualText
|
||||
>
|
||||
declare type TextInput = typeof TextInput
|
||||
declare type TextInputAndroidProps = {
|
||||
@@ -5997,7 +5995,7 @@ export {
|
||||
AlertOptions, // a0cdac0f
|
||||
AlertType, // 5ab91217
|
||||
AndroidKeyboardEvent, // e03becc8
|
||||
Animated, // f39d3c6f
|
||||
Animated, // ed7eb912
|
||||
AppConfig, // ebddad4b
|
||||
AppRegistry, // 6cdee1d6
|
||||
AppState, // 12012be5
|
||||
@@ -6217,7 +6215,7 @@ export {
|
||||
TVViewPropsIOS, // 330ce7b5
|
||||
TargetedEvent, // 16e98910
|
||||
TaskProvider, // 266dedf2
|
||||
Text, // 0620c789
|
||||
Text, // e55ac2e2
|
||||
TextContentType, // 239b3ecc
|
||||
TextInput, // 2e89b91d
|
||||
TextInputAndroidProps, // 3f09ce49
|
||||
|
||||
Reference in new issue
Block a user