Skip to content

Commit 79b4916

Browse files
iamAbhi-916Abhijeet Jha
andauthored
Added tooltip property for Text (#14470)
* Added tooltip property in Text.windows.js TextProps.windows.js for typescript to recognise it as an attribute of Text component * Added override Text.d.ts to src-win/Libraries/Text/ to add tooltip prop to Text component * Change files * Added Sample/text for tooltip prop tests * Added TextPropsWindows to include windows specific prop tooltip * updated TextProps interface to extednd TextPropsWindows * lint fix for Sample/text.tsx file --------- Co-authored-by: Abhijeet Jha <abhijeetjha@microsoft.com>
1 parent 6a4d3c7 commit 79b4916

File tree

4 files changed

+258
-2
lines changed

4 files changed

+258
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "none",
3+
"comment": "Added override Text.d.ts to src-win/Libraries/Text/ to add tooltip prop to Text component",
4+
"packageName": "react-native-windows",
5+
"email": "email not defined",
6+
"dependentChangeType": "none"
7+
}

packages/playground/Samples/text.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
*/
66

77
import React from 'react';
8-
import {AppRegistry, StyleSheet, Text, View} from 'react-native';
8+
import {AppRegistry, StyleSheet, View} from 'react-native';
9+
import {Text} from 'react-native-windows';
910

1011
export default class Bootstrap extends React.Component {
1112
render() {
1213
return (
1314
<View style={styles.container}>
1415
<Text style={styles.welcome}>Welcome to React Native!</Text>
16+
<Text
17+
style={styles.welcome}
18+
tooltip=" tooltip message for the text"
19+
accessible={true}
20+
selectable={true}>
21+
Click here : This is a text with a tooltip.
22+
</Text>
1523
</View>
1624
);
1725
}

vnext/overrides.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,13 @@
557557
"type": "platform",
558558
"file": "src-win/Libraries/StyleSheet/PlatformColorValueTypes.windows.js"
559559
},
560+
{
561+
"type": "derived",
562+
"file": "src-win/Libraries/Text/Text.d.ts",
563+
"baseFile": "packages/react-native/Libraries/Text/Text.d.ts",
564+
"baseHash": "21dab7f71254c429d592827ab313f77c18baeda1",
565+
"issue": 0
566+
},
560567
{
561568
"type": "derived",
562569
"file": "src-win/Libraries/Text/Text.windows.js",
@@ -623,4 +630,4 @@
623630
"baseHash": "fa0f34a2de33b641bd63863629087644796d8b59"
624631
}
625632
]
626-
}
633+
}
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
import type * as React from 'react';
11+
import {Constructor} from '../../types/private/Utilities';
12+
import {AccessibilityProps} from '../Components/View/ViewAccessibility';
13+
import {NativeMethods} from '../../types/public/ReactNativeTypes';
14+
import {ColorValue, StyleProp} from '../StyleSheet/StyleSheet';
15+
import {TextStyle, ViewStyle} from '../StyleSheet/StyleSheetTypes';
16+
import {
17+
GestureResponderEvent,
18+
LayoutChangeEvent,
19+
NativeSyntheticEvent,
20+
TextLayoutEventData,
21+
} from '../Types/CoreEventTypes';
22+
23+
export interface TextPropsIOS {
24+
/**
25+
* Specifies whether font should be scaled down automatically to fit given style constraints.
26+
*/
27+
adjustsFontSizeToFit?: boolean | undefined;
28+
29+
/**
30+
* The Dynamic Type scale ramp to apply to this element on iOS.
31+
*/
32+
dynamicTypeRamp?:
33+
| 'caption2'
34+
| 'caption1'
35+
| 'footnote'
36+
| 'subheadline'
37+
| 'callout'
38+
| 'body'
39+
| 'headline'
40+
| 'title3'
41+
| 'title2'
42+
| 'title1'
43+
| 'largeTitle'
44+
| undefined;
45+
46+
/**
47+
* When `true`, no visual change is made when text is pressed down. By
48+
* default, a gray oval highlights the text on press down.
49+
*/
50+
suppressHighlighting?: boolean | undefined;
51+
52+
/**
53+
* Set line break strategy on iOS.
54+
*/
55+
lineBreakStrategyIOS?:
56+
| 'none'
57+
| 'standard'
58+
| 'hangul-word'
59+
| 'push-out'
60+
| undefined;
61+
}
62+
63+
export interface TextPropsAndroid {
64+
/**
65+
* Specifies the disabled state of the text view for testing purposes.
66+
*/
67+
disabled?: boolean | undefined;
68+
69+
/**
70+
* Lets the user select text, to use the native copy and paste functionality.
71+
*/
72+
selectable?: boolean | undefined;
73+
74+
/**
75+
* The highlight color of the text.
76+
*/
77+
selectionColor?: ColorValue | undefined;
78+
79+
/**
80+
* Set text break strategy on Android API Level 23+
81+
* default is `highQuality`.
82+
*/
83+
textBreakStrategy?: 'simple' | 'highQuality' | 'balanced' | undefined;
84+
85+
/**
86+
* Determines the types of data converted to clickable URLs in the text element.
87+
* By default no data types are detected.
88+
*/
89+
dataDetectorType?:
90+
| null
91+
| 'phoneNumber'
92+
| 'link'
93+
| 'email'
94+
| 'none'
95+
| 'all'
96+
| undefined;
97+
98+
/**
99+
* Hyphenation strategy
100+
*/
101+
android_hyphenationFrequency?: 'normal' | 'none' | 'full' | undefined;
102+
}
103+
104+
export interface TextPropsWindows {
105+
/**
106+
* The tooltip to show when the text is clicked.
107+
*/
108+
// [Windows
109+
tooltip?: string | undefined;
110+
// Windows]
111+
}
112+
113+
// https://reactnative.dev/docs/text#props
114+
export interface TextProps
115+
extends TextPropsIOS,
116+
TextPropsAndroid,
117+
TextPropsWindows,
118+
AccessibilityProps {
119+
/**
120+
* Specifies whether fonts should scale to respect Text Size accessibility settings.
121+
* The default is `true`.
122+
*/
123+
allowFontScaling?: boolean | undefined;
124+
125+
children?: React.ReactNode | undefined;
126+
127+
/**
128+
* This can be one of the following values:
129+
*
130+
* - `head` - The line is displayed so that the end fits in the container and the missing text
131+
* at the beginning of the line is indicated by an ellipsis glyph. e.g., "...wxyz"
132+
* - `middle` - The line is displayed so that the beginning and end fit in the container and the
133+
* missing text in the middle is indicated by an ellipsis glyph. "ab...yz"
134+
* - `tail` - The line is displayed so that the beginning fits in the container and the
135+
* missing text at the end of the line is indicated by an ellipsis glyph. e.g., "abcd..."
136+
* - `clip` - Lines are not drawn past the edge of the text container.
137+
*
138+
* The default is `tail`.
139+
*
140+
* `numberOfLines` must be set in conjunction with this prop.
141+
*
142+
* > `clip` is working only for iOS
143+
*/
144+
ellipsizeMode?: 'head' | 'middle' | 'tail' | 'clip' | undefined;
145+
146+
/**
147+
* Used to reference react managed views from native code.
148+
*/
149+
id?: string | undefined;
150+
151+
/**
152+
* Line Break mode. Works only with numberOfLines.
153+
* clip is working only for iOS
154+
*/
155+
lineBreakMode?: 'head' | 'middle' | 'tail' | 'clip' | undefined;
156+
157+
/**
158+
* Used to truncate the text with an ellipsis after computing the text
159+
* layout, including line wrapping, such that the total number of lines
160+
* does not exceed this number.
161+
*
162+
* This prop is commonly used with `ellipsizeMode`.
163+
*/
164+
numberOfLines?: number | undefined;
165+
166+
/**
167+
* Invoked on mount and layout changes with
168+
*
169+
* {nativeEvent: { layout: {x, y, width, height}}}.
170+
*/
171+
onLayout?: ((event: LayoutChangeEvent) => void) | undefined;
172+
173+
/**
174+
* Invoked on Text layout
175+
*/
176+
onTextLayout?:
177+
| ((event: NativeSyntheticEvent<TextLayoutEventData>) => void)
178+
| undefined;
179+
180+
/**
181+
* This function is called on press.
182+
* Text intrinsically supports press handling with a default highlight state (which can be disabled with suppressHighlighting).
183+
*/
184+
onPress?: ((event: GestureResponderEvent) => void) | undefined;
185+
186+
onPressIn?: ((event: GestureResponderEvent) => void) | undefined;
187+
onPressOut?: ((event: GestureResponderEvent) => void) | undefined;
188+
189+
/**
190+
* This function is called on long press.
191+
* e.g., `onLongPress={this.increaseSize}>``
192+
*/
193+
onLongPress?: ((event: GestureResponderEvent) => void) | undefined;
194+
195+
/**
196+
* @see https://reactnative.dev/docs/text#style
197+
*/
198+
style?: StyleProp<TextStyle> | undefined;
199+
200+
/**
201+
* Used to locate this view in end-to-end tests.
202+
*/
203+
testID?: string | undefined;
204+
205+
/**
206+
* Used to reference react managed views from native code.
207+
*/
208+
nativeID?: string | undefined;
209+
210+
/**
211+
* Specifies largest possible scale a font can reach when allowFontScaling is enabled. Possible values:
212+
* - null/undefined (default): inherit from the parent node or the global default (0)
213+
* - 0: no max, ignore parent/global default
214+
* - >= 1: sets the maxFontSizeMultiplier of this node to this value
215+
*/
216+
maxFontSizeMultiplier?: number | null | undefined;
217+
218+
/**
219+
* Specifies smallest possible scale a font can reach when adjustsFontSizeToFit is enabled. (values 0.01-1.0).
220+
*/
221+
minimumFontScale?: number | undefined;
222+
223+
/**
224+
* Controls how touch events are handled. Similar to `View`'s `pointerEvents`.
225+
*/
226+
pointerEvents?: ViewStyle['pointerEvents'] | undefined;
227+
}
228+
229+
/**
230+
* A React component for displaying text which supports nesting, styling, and touch handling.
231+
*/
232+
declare class TextComponent extends React.Component<TextProps> {}
233+
declare const TextBase: Constructor<NativeMethods> & typeof TextComponent;
234+
export class Text extends TextBase {}

0 commit comments

Comments
 (0)