@bsky.app/react-native-uitextview 2.3.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/LICENSE +20 -0
- package/README.md +188 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/CMakeLists.txt +28 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/RNUITextViewSpec-generated.cpp +22 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/RNUITextViewSpec.h +24 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/ComponentDescriptors.cpp +23 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/ComponentDescriptors.h +25 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/EventEmitters.cpp +61 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/EventEmitters.h +49 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/Props.cpp +151 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/Props.h +236 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/RNUITextViewSpecJSI.h +19 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/ShadowNodes.cpp +18 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/ShadowNodes.h +43 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/States.cpp +16 -0
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNUITextViewSpec/States.h +22 -0
- package/ios/RNUITextView.h +13 -0
- package/ios/RNUITextView.mm +338 -0
- package/ios/RNUITextViewChild.h +24 -0
- package/ios/RNUITextViewChild.mm +72 -0
- package/ios/RNUITextViewChildComponentDescriptor.h +13 -0
- package/ios/RNUITextViewChildShadowNode.cpp +6 -0
- package/ios/RNUITextViewChildShadowNode.h +16 -0
- package/ios/RNUITextViewComponentDescriptor.h +13 -0
- package/ios/RNUITextViewManager.mm +36 -0
- package/ios/RNUITextViewShadowNode.cpp +139 -0
- package/ios/RNUITextViewShadowNode.h +48 -0
- package/ios/generated/build/generated/ios/ReactCodegen/RNUITextViewSpec/RNUITextViewSpec-generated.mm +16 -0
- package/ios/generated/build/generated/ios/ReactCodegen/RNUITextViewSpec/RNUITextViewSpec.h +38 -0
- package/ios/generated/build/generated/ios/ReactCodegen/RNUITextViewSpecJSI.h +19 -0
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/ComponentDescriptors.cpp +23 -0
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/ComponentDescriptors.h +25 -0
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/EventEmitters.cpp +61 -0
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/EventEmitters.h +49 -0
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/Props.cpp +151 -0
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/Props.h +236 -0
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/RCTComponentViewHelpers.h +24 -0
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/ShadowNodes.cpp +18 -0
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/ShadowNodes.h +43 -0
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/States.cpp +16 -0
- package/ios/generated/build/generated/ios/ReactCodegen/react/renderer/components/RNUITextViewSpec/States.h +22 -0
- package/lib/commonjs/RNUITextViewChildNativeComponent.ts +49 -0
- package/lib/commonjs/RNUITextViewNativeComponent.ts +53 -0
- package/lib/commonjs/Text.js +111 -0
- package/lib/commonjs/Text.js.map +1 -0
- package/lib/commonjs/Text.web.js +23 -0
- package/lib/commonjs/Text.web.js.map +1 -0
- package/lib/commonjs/index.js +17 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/util.js +66 -0
- package/lib/commonjs/util.js.map +1 -0
- package/lib/module/RNUITextViewChildNativeComponent.ts +49 -0
- package/lib/module/RNUITextViewNativeComponent.ts +53 -0
- package/lib/module/Text.js +106 -0
- package/lib/module/Text.js.map +1 -0
- package/lib/module/Text.web.js +19 -0
- package/lib/module/Text.web.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/util.js +62 -0
- package/lib/module/util.js.map +1 -0
- package/lib/typescript/commonjs/example/src/App.d.ts +3 -0
- package/lib/typescript/commonjs/example/src/App.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/RNUITextViewChildNativeComponent.d.ts +29 -0
- package/lib/typescript/commonjs/src/RNUITextViewChildNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/RNUITextViewNativeComponent.d.ts +43 -0
- package/lib/typescript/commonjs/src/RNUITextViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/Text.d.ts +25 -0
- package/lib/typescript/commonjs/src/Text.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/Text.web.d.ts +19 -0
- package/lib/typescript/commonjs/src/Text.web.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +2 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/util.d.ts +163 -0
- package/lib/typescript/commonjs/src/util.d.ts.map +1 -0
- package/lib/typescript/module/example/src/App.d.ts +3 -0
- package/lib/typescript/module/example/src/App.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/RNUITextViewChildNativeComponent.d.ts +29 -0
- package/lib/typescript/module/src/RNUITextViewChildNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/RNUITextViewNativeComponent.d.ts +43 -0
- package/lib/typescript/module/src/RNUITextViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/Text.d.ts +25 -0
- package/lib/typescript/module/src/Text.d.ts.map +1 -0
- package/lib/typescript/module/src/Text.web.d.ts +19 -0
- package/lib/typescript/module/src/Text.web.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +2 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/util.d.ts +163 -0
- package/lib/typescript/module/src/util.d.ts.map +1 -0
- package/package.json +185 -0
- package/react-native-uitextview.podspec +34 -0
- package/react-native.config.js +28 -0
- package/scripts/ensure-rnc-cli-executable.js +19 -0
- package/src/RNUITextViewChildNativeComponent.ts +49 -0
- package/src/RNUITextViewNativeComponent.ts +53 -0
- package/src/Text.tsx +125 -0
- package/src/Text.web.tsx +22 -0
- package/src/index.tsx +1 -0
- package/src/util.ts +67 -0
package/src/Text.tsx
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
Platform,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
Text as RNText,
|
|
6
|
+
type TextProps,
|
|
7
|
+
type ViewStyle,
|
|
8
|
+
} from 'react-native'
|
|
9
|
+
import RNUITextViewChildNativeComponent from './RNUITextViewChildNativeComponent'
|
|
10
|
+
import RNUITextViewNativeComponent from './RNUITextViewNativeComponent'
|
|
11
|
+
import {flattenStyles} from './util'
|
|
12
|
+
|
|
13
|
+
const TextAncestorContext = React.createContext<[boolean, ViewStyle]>([
|
|
14
|
+
false,
|
|
15
|
+
StyleSheet.create({}),
|
|
16
|
+
])
|
|
17
|
+
|
|
18
|
+
const textDefaults: TextProps = {
|
|
19
|
+
allowFontScaling: true,
|
|
20
|
+
selectable: true,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const useTextAncestorContext = () => React.useContext(TextAncestorContext)
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Event fired by `onSelectionChange`. `start`/`end` are 0-based UTF-16 indices
|
|
27
|
+
* into the rendered string. `start === end` means the selection was cleared.
|
|
28
|
+
*/
|
|
29
|
+
export type SelectionChangeEvent = {
|
|
30
|
+
nativeEvent: {target: number; start: number; end: number}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type UITextViewProps = TextProps & {
|
|
34
|
+
uiTextView?: boolean
|
|
35
|
+
/**
|
|
36
|
+
* Fired when the native text selection changes. Only fires on iOS when
|
|
37
|
+
* `uiTextView` is true. Note: fires on every selection-edge adjustment
|
|
38
|
+
* (e.g. dragging a selection handle), so consumers driving expensive work
|
|
39
|
+
* off this event should debounce.
|
|
40
|
+
*/
|
|
41
|
+
onSelectionChange?: (event: SelectionChangeEvent) => void
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function UITextViewChild({style, children, ...rest}: UITextViewProps) {
|
|
45
|
+
const [isAncestor, rootStyle] = useTextAncestorContext()
|
|
46
|
+
|
|
47
|
+
// Flatten the styles, and apply the root styles when needed
|
|
48
|
+
const flattenedStyle = React.useMemo(
|
|
49
|
+
() => flattenStyles(rootStyle, style),
|
|
50
|
+
[rootStyle, style],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
if (!isAncestor) {
|
|
54
|
+
return (
|
|
55
|
+
<TextAncestorContext.Provider value={[true, flattenedStyle]}>
|
|
56
|
+
<RNUITextViewNativeComponent
|
|
57
|
+
{...textDefaults}
|
|
58
|
+
{...rest}
|
|
59
|
+
// ellipsizeMode={rest.ellipsizeMode ?? rest.lineBreakMode ?? 'tail'}
|
|
60
|
+
style={[flattenedStyle]}
|
|
61
|
+
// @ts-expect-error Weirdness
|
|
62
|
+
onPress={undefined}
|
|
63
|
+
onLongPress={undefined}>
|
|
64
|
+
{React.Children.toArray(children).map((c, index) => {
|
|
65
|
+
if (React.isValidElement(c)) {
|
|
66
|
+
return c
|
|
67
|
+
} else if (typeof c === 'string' || typeof c === 'number') {
|
|
68
|
+
return (
|
|
69
|
+
// @ts-expect-error @TODO fix this type
|
|
70
|
+
<RNUITextViewChildNativeComponent
|
|
71
|
+
key={index}
|
|
72
|
+
style={flattenedStyle}
|
|
73
|
+
text={c.toString()}
|
|
74
|
+
{...rest}
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
return null
|
|
79
|
+
})}
|
|
80
|
+
</RNUITextViewNativeComponent>
|
|
81
|
+
</TextAncestorContext.Provider>
|
|
82
|
+
)
|
|
83
|
+
} else {
|
|
84
|
+
return (
|
|
85
|
+
<>
|
|
86
|
+
{React.Children.toArray(children).map((c, index) => {
|
|
87
|
+
if (React.isValidElement(c)) {
|
|
88
|
+
return c
|
|
89
|
+
} else if (typeof c === 'string' || typeof c === 'number') {
|
|
90
|
+
return (
|
|
91
|
+
// @ts-expect-error @TODO fix this type
|
|
92
|
+
<RNUITextViewChildNativeComponent
|
|
93
|
+
key={index}
|
|
94
|
+
style={flattenedStyle}
|
|
95
|
+
text={c.toString()}
|
|
96
|
+
{...rest}
|
|
97
|
+
/>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return null
|
|
102
|
+
})}
|
|
103
|
+
</>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function UITextViewInner(props: UITextViewProps) {
|
|
109
|
+
const [isAncestor] = useTextAncestorContext()
|
|
110
|
+
|
|
111
|
+
// Even if the uiTextView prop is set, we can still default to using
|
|
112
|
+
// normal selection (i.e. base RN text) if the text doesn't need to be
|
|
113
|
+
// selectable
|
|
114
|
+
if ((!props.selectable || !props.uiTextView) && !isAncestor) {
|
|
115
|
+
return <RNText {...props} />
|
|
116
|
+
}
|
|
117
|
+
return <UITextViewChild {...props} />
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function UITextView(props: UITextViewProps) {
|
|
121
|
+
if (Platform.OS !== 'ios') {
|
|
122
|
+
return <RNText {...props} />
|
|
123
|
+
}
|
|
124
|
+
return <UITextViewInner {...props} />
|
|
125
|
+
}
|
package/src/Text.web.tsx
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {Text as RNText, type TextProps} from 'react-native'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Event fired by `onSelectionChange`. This event is only available when using
|
|
5
|
+
* the native UITextView implementation on iOS.
|
|
6
|
+
*/
|
|
7
|
+
export type SelectionChangeEvent = {
|
|
8
|
+
nativeEvent: {target: number; start: number; end: number}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type UITextViewProps = TextProps & {
|
|
12
|
+
uiTextView?: boolean
|
|
13
|
+
onSelectionChange?: (event: SelectionChangeEvent) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function UITextView({
|
|
17
|
+
uiTextView: _uiTextView,
|
|
18
|
+
onSelectionChange: _onSelectionChange,
|
|
19
|
+
...props
|
|
20
|
+
}: UITextViewProps) {
|
|
21
|
+
return <RNText {...props} />
|
|
22
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Text'
|
package/src/util.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {type StyleProp, StyleSheet, type TextStyle} from 'react-native'
|
|
2
|
+
import type {NativeFontWeight} from './RNUITextViewChildNativeComponent'
|
|
3
|
+
|
|
4
|
+
export function flattenStyles(
|
|
5
|
+
rootStyle: TextStyle,
|
|
6
|
+
style: StyleProp<TextStyle>,
|
|
7
|
+
) {
|
|
8
|
+
const flattenedStyle = StyleSheet.flatten([rootStyle, style]) as TextStyle
|
|
9
|
+
return {
|
|
10
|
+
...flattenedStyle,
|
|
11
|
+
fontWeight: fontWeightToNativeProp(flattenedStyle.fontWeight ?? 'normal'),
|
|
12
|
+
backgroundColor: flattenedStyle.backgroundColor
|
|
13
|
+
? flattenedStyle.backgroundColor
|
|
14
|
+
: 'transparent',
|
|
15
|
+
shadowOffset: flattenedStyle.shadowOffset
|
|
16
|
+
? flattenedStyle.shadowOffset
|
|
17
|
+
: {width: 0, height: 0},
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Codegen doesn't like using integer values for enums (c++ L) so we'll conver them to the proper native prop
|
|
22
|
+
// value before returning flattened styles.
|
|
23
|
+
function fontWeightToNativeProp(
|
|
24
|
+
fontWeight: TextStyle['fontWeight'],
|
|
25
|
+
): NativeFontWeight {
|
|
26
|
+
switch (fontWeight) {
|
|
27
|
+
case 'normal':
|
|
28
|
+
return 'normal'
|
|
29
|
+
case 'bold':
|
|
30
|
+
return 'bold'
|
|
31
|
+
case 100:
|
|
32
|
+
case '100':
|
|
33
|
+
case 'ultralight':
|
|
34
|
+
return 'ultraLight'
|
|
35
|
+
case 200:
|
|
36
|
+
case '200':
|
|
37
|
+
return 'ultraLight'
|
|
38
|
+
case 300:
|
|
39
|
+
case '300':
|
|
40
|
+
case 'light':
|
|
41
|
+
return 'light'
|
|
42
|
+
case 400:
|
|
43
|
+
case '400':
|
|
44
|
+
case 'regular':
|
|
45
|
+
return 'normal'
|
|
46
|
+
case 500:
|
|
47
|
+
case '500':
|
|
48
|
+
case 'medium':
|
|
49
|
+
return 'medium'
|
|
50
|
+
case 600:
|
|
51
|
+
case '600':
|
|
52
|
+
case 'semibold':
|
|
53
|
+
return 'semibold'
|
|
54
|
+
case 700:
|
|
55
|
+
case '700':
|
|
56
|
+
return 'semibold'
|
|
57
|
+
case 800:
|
|
58
|
+
case '800':
|
|
59
|
+
return 'bold'
|
|
60
|
+
case 900:
|
|
61
|
+
case '900':
|
|
62
|
+
case 'heavy':
|
|
63
|
+
return 'heavy'
|
|
64
|
+
default:
|
|
65
|
+
return 'normal'
|
|
66
|
+
}
|
|
67
|
+
}
|