@bsky.app/react-native-uitextview 2.4.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/Props.cpp +31 -1
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/Props.h +6 -0
- package/ios/RNUITextView.mm +503 -41
- package/ios/RNUITextViewShadowNode.cpp +17 -2
- package/ios/RNUITextViewShadowNode.h +17 -1
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/Props.cpp +31 -1
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/Props.h +6 -0
- package/lib/commonjs/RNUITextViewChildNativeComponent.ts +9 -0
- package/lib/commonjs/Text.js +81 -23
- package/lib/commonjs/Text.js.map +1 -1
- package/lib/commonjs/press.js +23 -0
- package/lib/commonjs/press.js.map +1 -0
- package/lib/module/RNUITextViewChildNativeComponent.ts +9 -0
- package/lib/module/Text.js +82 -24
- package/lib/module/Text.js.map +1 -1
- package/lib/module/press.js +19 -0
- package/lib/module/press.js.map +1 -0
- package/lib/typescript/commonjs/example/src/App.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/RNUITextViewChildNativeComponent.d.ts +9 -0
- package/lib/typescript/commonjs/src/RNUITextViewChildNativeComponent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/Text.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/press.d.ts +10 -0
- package/lib/typescript/commonjs/src/press.d.ts.map +1 -0
- package/lib/typescript/module/example/src/App.d.ts.map +1 -1
- package/lib/typescript/module/src/RNUITextViewChildNativeComponent.d.ts +9 -0
- package/lib/typescript/module/src/RNUITextViewChildNativeComponent.d.ts.map +1 -1
- package/lib/typescript/module/src/Text.d.ts.map +1 -1
- package/lib/typescript/module/src/press.d.ts +10 -0
- package/lib/typescript/module/src/press.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/RNUITextViewChildNativeComponent.ts +9 -0
- package/src/Text.tsx +80 -11
- package/src/press.ts +36 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../../../src/Text.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,SAAS,EAEf,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../../../src/Text.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,SAAS,EAEf,MAAM,cAAc,CAAA;AAuBrB;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,EAAE;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAC,CAAA;CAC1D,CAAA;AAED,KAAK,eAAe,GAAG,SAAS,GAAG;IACjC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAA;CAC1D,CAAA;AA6ID,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,+BAKhD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TextProps } from 'react-native';
|
|
2
|
+
export type PressContext = {
|
|
3
|
+
highlightGroup?: string;
|
|
4
|
+
suppressHighlighting?: boolean;
|
|
5
|
+
pressRetentionOffset?: TextProps['pressRetentionOffset'];
|
|
6
|
+
onPress?: TextProps['onPress'];
|
|
7
|
+
onLongPress?: TextProps['onLongPress'];
|
|
8
|
+
};
|
|
9
|
+
export declare function resolvePressContext(ownHighlightGroup: string, props: Pick<TextProps, 'onPress' | 'onLongPress' | 'pressRetentionOffset' | 'suppressHighlighting'>, ancestor: PressContext): PressContext;
|
|
10
|
+
//# sourceMappingURL=press.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"press.d.ts","sourceRoot":"","sources":["../../../../src/press.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAA;AAE3C,MAAM,MAAM,YAAY,GAAG;IACzB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,oBAAoB,CAAC,EAAE,SAAS,CAAC,sBAAsB,CAAC,CAAA;IACxD,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;IAC9B,WAAW,CAAC,EAAE,SAAS,CAAC,aAAa,CAAC,CAAA;CACvC,CAAA;AAED,wBAAgB,mBAAmB,CACjC,iBAAiB,EAAE,MAAM,EACzB,KAAK,EAAE,IAAI,CACT,SAAS,EACT,SAAS,GAAG,aAAa,GAAG,sBAAsB,GAAG,sBAAsB,CAC5E,EACD,QAAQ,EAAE,YAAY,GACrB,YAAY,CAkBd"}
|
package/package.json
CHANGED
|
@@ -40,6 +40,15 @@ interface NativeProps extends ViewProps {
|
|
|
40
40
|
textDecorationColor?: ColorValue
|
|
41
41
|
textAlign?: CodegenTypes.WithDefault<TextAlign, 'auto'>
|
|
42
42
|
shadowRadius?: CodegenTypes.WithDefault<CodegenTypes.Float, 0>
|
|
43
|
+
/** Internal identifier used to highlight all fragments in a pressable Text. */
|
|
44
|
+
highlightGroup?: string
|
|
45
|
+
/** Internal copy of Text's suppressHighlighting prop. */
|
|
46
|
+
suppressHighlighting?: boolean
|
|
47
|
+
/** Internal expansion of the owning Text's press-retention rectangle. */
|
|
48
|
+
pressRetentionOffsetTop?: CodegenTypes.WithDefault<CodegenTypes.Float, 20>
|
|
49
|
+
pressRetentionOffsetRight?: CodegenTypes.WithDefault<CodegenTypes.Float, 20>
|
|
50
|
+
pressRetentionOffsetBottom?: CodegenTypes.WithDefault<CodegenTypes.Float, 30>
|
|
51
|
+
pressRetentionOffsetLeft?: CodegenTypes.WithDefault<CodegenTypes.Float, 20>
|
|
43
52
|
onPress?: CodegenTypes.BubblingEventHandler<TargetedEvent>
|
|
44
53
|
onLongPress?: CodegenTypes.BubblingEventHandler<TargetedEvent>
|
|
45
54
|
}
|
package/src/Text.tsx
CHANGED
|
@@ -8,12 +8,18 @@ import {
|
|
|
8
8
|
} from 'react-native'
|
|
9
9
|
import RNUITextViewChildNativeComponent from './RNUITextViewChildNativeComponent'
|
|
10
10
|
import RNUITextViewNativeComponent from './RNUITextViewNativeComponent'
|
|
11
|
+
import {resolvePressContext, type PressContext} from './press'
|
|
11
12
|
import {flattenStyles} from './util'
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
type TextAncestorContextValue = PressContext & {
|
|
15
|
+
isAncestor: boolean
|
|
16
|
+
rootStyle: ViewStyle
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const TextAncestorContext = React.createContext<TextAncestorContextValue>({
|
|
20
|
+
isAncestor: false,
|
|
21
|
+
rootStyle: StyleSheet.create({}),
|
|
22
|
+
})
|
|
17
23
|
|
|
18
24
|
const textDefaults: TextProps = {
|
|
19
25
|
allowFontScaling: true,
|
|
@@ -42,7 +48,38 @@ type UITextViewProps = TextProps & {
|
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
function UITextViewChild({style, children, ...rest}: UITextViewProps) {
|
|
45
|
-
const
|
|
51
|
+
const {
|
|
52
|
+
isAncestor,
|
|
53
|
+
rootStyle,
|
|
54
|
+
highlightGroup: ancestorHighlightGroup,
|
|
55
|
+
suppressHighlighting: ancestorSuppressHighlighting,
|
|
56
|
+
pressRetentionOffset: ancestorPressRetentionOffset,
|
|
57
|
+
onPress: ancestorOnPress,
|
|
58
|
+
onLongPress: ancestorOnLongPress,
|
|
59
|
+
} = useTextAncestorContext()
|
|
60
|
+
const ownHighlightGroup = React.useId()
|
|
61
|
+
const {
|
|
62
|
+
highlightGroup,
|
|
63
|
+
suppressHighlighting,
|
|
64
|
+
pressRetentionOffset,
|
|
65
|
+
onPress,
|
|
66
|
+
onLongPress,
|
|
67
|
+
} = resolvePressContext(ownHighlightGroup, rest, {
|
|
68
|
+
highlightGroup: ancestorHighlightGroup,
|
|
69
|
+
suppressHighlighting: ancestorSuppressHighlighting,
|
|
70
|
+
pressRetentionOffset: ancestorPressRetentionOffset,
|
|
71
|
+
onPress: ancestorOnPress,
|
|
72
|
+
onLongPress: ancestorOnLongPress,
|
|
73
|
+
})
|
|
74
|
+
// The native event currently contains only `target`, while TextProps types
|
|
75
|
+
// these callbacks as full gesture events. Preserve the existing public type
|
|
76
|
+
// and adapt it only at the private Codegen boundary.
|
|
77
|
+
const nativeOnPress = onPress as React.ComponentProps<
|
|
78
|
+
typeof RNUITextViewChildNativeComponent
|
|
79
|
+
>['onPress']
|
|
80
|
+
const nativeOnLongPress = onLongPress as React.ComponentProps<
|
|
81
|
+
typeof RNUITextViewChildNativeComponent
|
|
82
|
+
>['onLongPress']
|
|
46
83
|
|
|
47
84
|
// Flatten the styles, and apply the root styles when needed
|
|
48
85
|
const flattenedStyle = React.useMemo(
|
|
@@ -52,7 +89,16 @@ function UITextViewChild({style, children, ...rest}: UITextViewProps) {
|
|
|
52
89
|
|
|
53
90
|
if (!isAncestor) {
|
|
54
91
|
return (
|
|
55
|
-
<TextAncestorContext.Provider
|
|
92
|
+
<TextAncestorContext.Provider
|
|
93
|
+
value={{
|
|
94
|
+
isAncestor: true,
|
|
95
|
+
rootStyle: flattenedStyle,
|
|
96
|
+
highlightGroup,
|
|
97
|
+
suppressHighlighting,
|
|
98
|
+
pressRetentionOffset,
|
|
99
|
+
onPress,
|
|
100
|
+
onLongPress,
|
|
101
|
+
}}>
|
|
56
102
|
<RNUITextViewNativeComponent
|
|
57
103
|
{...textDefaults}
|
|
58
104
|
{...rest}
|
|
@@ -66,12 +112,19 @@ function UITextViewChild({style, children, ...rest}: UITextViewProps) {
|
|
|
66
112
|
return c
|
|
67
113
|
} else if (typeof c === 'string' || typeof c === 'number') {
|
|
68
114
|
return (
|
|
69
|
-
// @ts-expect-error @TODO fix this type
|
|
70
115
|
<RNUITextViewChildNativeComponent
|
|
71
116
|
key={index}
|
|
72
117
|
style={flattenedStyle}
|
|
73
118
|
text={c.toString()}
|
|
74
119
|
{...rest}
|
|
120
|
+
highlightGroup={highlightGroup}
|
|
121
|
+
suppressHighlighting={suppressHighlighting}
|
|
122
|
+
pressRetentionOffsetTop={pressRetentionOffset?.top}
|
|
123
|
+
pressRetentionOffsetRight={pressRetentionOffset?.right}
|
|
124
|
+
pressRetentionOffsetBottom={pressRetentionOffset?.bottom}
|
|
125
|
+
pressRetentionOffsetLeft={pressRetentionOffset?.left}
|
|
126
|
+
onPress={nativeOnPress}
|
|
127
|
+
onLongPress={nativeOnLongPress}
|
|
75
128
|
/>
|
|
76
129
|
)
|
|
77
130
|
}
|
|
@@ -82,31 +135,47 @@ function UITextViewChild({style, children, ...rest}: UITextViewProps) {
|
|
|
82
135
|
)
|
|
83
136
|
} else {
|
|
84
137
|
return (
|
|
85
|
-
|
|
138
|
+
<TextAncestorContext.Provider
|
|
139
|
+
value={{
|
|
140
|
+
isAncestor: true,
|
|
141
|
+
rootStyle: flattenedStyle,
|
|
142
|
+
highlightGroup,
|
|
143
|
+
suppressHighlighting,
|
|
144
|
+
pressRetentionOffset,
|
|
145
|
+
onPress,
|
|
146
|
+
onLongPress,
|
|
147
|
+
}}>
|
|
86
148
|
{React.Children.toArray(children).map((c, index) => {
|
|
87
149
|
if (React.isValidElement(c)) {
|
|
88
150
|
return c
|
|
89
151
|
} else if (typeof c === 'string' || typeof c === 'number') {
|
|
90
152
|
return (
|
|
91
|
-
// @ts-expect-error @TODO fix this type
|
|
92
153
|
<RNUITextViewChildNativeComponent
|
|
93
154
|
key={index}
|
|
94
155
|
style={flattenedStyle}
|
|
95
156
|
text={c.toString()}
|
|
96
157
|
{...rest}
|
|
158
|
+
highlightGroup={highlightGroup}
|
|
159
|
+
suppressHighlighting={suppressHighlighting}
|
|
160
|
+
pressRetentionOffsetTop={pressRetentionOffset?.top}
|
|
161
|
+
pressRetentionOffsetRight={pressRetentionOffset?.right}
|
|
162
|
+
pressRetentionOffsetBottom={pressRetentionOffset?.bottom}
|
|
163
|
+
pressRetentionOffsetLeft={pressRetentionOffset?.left}
|
|
164
|
+
onPress={nativeOnPress}
|
|
165
|
+
onLongPress={nativeOnLongPress}
|
|
97
166
|
/>
|
|
98
167
|
)
|
|
99
168
|
}
|
|
100
169
|
|
|
101
170
|
return null
|
|
102
171
|
})}
|
|
103
|
-
|
|
172
|
+
</TextAncestorContext.Provider>
|
|
104
173
|
)
|
|
105
174
|
}
|
|
106
175
|
}
|
|
107
176
|
|
|
108
177
|
function UITextViewInner(props: UITextViewProps) {
|
|
109
|
-
const
|
|
178
|
+
const {isAncestor} = useTextAncestorContext()
|
|
110
179
|
|
|
111
180
|
// Even if the uiTextView prop is set, we can still default to using
|
|
112
181
|
// normal selection (i.e. base RN text) if the text doesn't need to be
|
package/src/press.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {TextProps} from 'react-native'
|
|
2
|
+
|
|
3
|
+
export type PressContext = {
|
|
4
|
+
highlightGroup?: string
|
|
5
|
+
suppressHighlighting?: boolean
|
|
6
|
+
pressRetentionOffset?: TextProps['pressRetentionOffset']
|
|
7
|
+
onPress?: TextProps['onPress']
|
|
8
|
+
onLongPress?: TextProps['onLongPress']
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function resolvePressContext(
|
|
12
|
+
ownHighlightGroup: string,
|
|
13
|
+
props: Pick<
|
|
14
|
+
TextProps,
|
|
15
|
+
'onPress' | 'onLongPress' | 'pressRetentionOffset' | 'suppressHighlighting'
|
|
16
|
+
>,
|
|
17
|
+
ancestor: PressContext,
|
|
18
|
+
): PressContext {
|
|
19
|
+
const isPressable = props.onPress != null || props.onLongPress != null
|
|
20
|
+
if (!isPressable) {
|
|
21
|
+
return ancestor
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
// Keep handler capabilities in the identifier that native already uses to
|
|
26
|
+
// group highlighted fragments. This avoids a separate prop/state channel
|
|
27
|
+
// getting out of sync with the group and its event emitter.
|
|
28
|
+
highlightGroup: `${ownHighlightGroup}|${props.onPress ? 'p' : ''}${
|
|
29
|
+
props.onLongPress ? 'l' : ''
|
|
30
|
+
}`,
|
|
31
|
+
suppressHighlighting: props.suppressHighlighting === true,
|
|
32
|
+
pressRetentionOffset: props.pressRetentionOffset,
|
|
33
|
+
onPress: props.onPress,
|
|
34
|
+
onLongPress: props.onLongPress,
|
|
35
|
+
}
|
|
36
|
+
}
|