Skip to content

Commit

Permalink
Cherry pick tooltip support to 0.63 branch (facebook#713)
Browse files Browse the repository at this point in the history
* Add nullability checks (facebook#704)

* Update RCTCxxBridge.mm

* add nullability checks

* 63 tooltips

* Add Tooltip support (facebook#701)

Co-authored-by: chiuam <[email protected]>
  • Loading branch information
HeyImChris and chiuam authored Feb 9, 2021
1 parent db63bd0 commit f26243a
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Libraries/Components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ type ButtonProps = $ReadOnly<{|
* For arrow keys, add "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown",
*/
validKeysUp?: ?Array<string>,
/*
* Specifies the Tooltip for the view
*/
tooltip?: string,
// ]TODO(OSS Candidate ISS#2710739)
|}>;

Expand Down Expand Up @@ -189,6 +193,7 @@ class Button extends React.Component<ButtonProps> {
validKeysDown,
validKeysUp,
onKeyUp,
tooltip,
} = this.props;
const buttonStyles = [styles.button];
const textStyles = [styles.text];
Expand Down Expand Up @@ -237,6 +242,7 @@ class Button extends React.Component<ButtonProps> {
onKeyUp={onKeyUp}
validKeysDown={validKeysDown}
validKeysUp={validKeysUp}
tooltip={tooltip}
touchSoundDisabled={touchSoundDisabled}>
<View style={buttonStyles}>
<Text style={textStyles} disabled={disabled}>
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Components/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ type Props = $ReadOnly<{|
* Used to locate this view in UI automation tests.
*/
testID?: ?string,
/**
* Specifies the tooltip.
*/
tooltip?: ?string,
|}>;

/**
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,10 @@ export type Props = $ReadOnly<{|
forwardedRef?: ?ReactRefSetter<
React.ElementRef<HostComponent<mixed>> & ImperativeMethods,
>,
/*
* Specifies the tooltip.
*/
tooltip?: ?string,
|}>;

type ImperativeMethods = $ReadOnly<{|
Expand Down
5 changes: 5 additions & 0 deletions Libraries/Image/ImageProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,9 @@ export type ImageProps = {|

src?: empty,
children?: empty,

/**
* Specifies the Tooltip for the view
*/
tooltip?: ?string,
|};
1 change: 1 addition & 0 deletions Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const viewConfig = {
onTextLayout: true,
onInlineViewLayout: true,
dataDetectorType: true,
tooltip: true,
},
directEventTypes: {
topTextLayout: {
Expand Down
9 changes: 9 additions & 0 deletions Libraries/Text/TextProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,13 @@ export type TextProps = $ReadOnly<{|
* See https://reactnative.dev/docs/text.html#supperhighlighting
*/
suppressHighlighting?: ?boolean,

/**
* macOS Only
*/

/**
* Specifies the Tooltip for the button view
*/
tooltip?: ?string,
|}>;
120 changes: 120 additions & 0 deletions RNTester/js/examples/Tooltip/TooltipExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/

'use strict';

const React = require('react');
const {
Button,
Image,
Slider,
StyleSheet,
Text,
TextInput,
View,
} = require('react-native');

const styles = StyleSheet.create({
image: {
width: 38,
height: 38,
},
textInput: {
borderWidth: StyleSheet.hairlineWidth,
borderColor: '#0f0f0f',
flex: 1,
fontSize: 13,
padding: 4,
},
view: {
backgroundColor: '#3CE8DA',
padding: 10,
},
});

const image = {
uri: 'https://www.facebook.com/favicon.ico',
};

function SliderExample(props: React.ElementConfig<typeof Slider>) {
const [value, setValue] = React.useState(0);

return (
<View>
<Text>{value.toFixed(3)}</Text>
<Slider
{...props}
onValueChange={newValue => setValue(newValue)}
tooltip={value.toFixed(3)}
/>
</View>
);
}

exports.displayName = 'TooltipExample';
exports.framework = 'React';
exports.title = 'Tooltip';
exports.description = 'Examples that showcase tooltip in various components.';

exports.examples = [
{
title: 'Button',
description: ('Simple button to showcase tooltip.': string),
render: function(): React.Node {
return (
<Button
title="Hover me"
onPress={() => {}}
tooltip={'Button tooltip'}
/>
);
},
},
{
title: 'Text',
description: ('Simple text string to showcase tooltip.': string),
render: function(): React.Node {
return (
<Text tooltip={'Text tooltip'}>
Simple text string to showcase tooltip.
</Text>
);
},
},
{
title: 'Image',
description: ('Image to showcase tooltip.': string),
render: function(): React.Node {
return (
<Image source={image} style={styles.image} tooltip={'Facebook logo'} />
);
},
},
{
title: 'View',
description: ('Background color view to showcase tooltip.': string),
render: function(): React.Node {
return <View style={styles.view} tooltip={'Turquoise'} />;
},
},
{
title: 'Slider',
description: ('Tooltip displays the current value.': string),
render(): React.Element<any> {
return <SliderExample />;
},
},
{
title: 'TextInput',
render: function(): React.Node {
return <TextInput style={styles.textInput} tooltip={'Name'} />;
},
},
];
5 changes: 5 additions & 0 deletions RNTester/js/utils/RNTesterList.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ const ComponentExamples: Array<RNTesterExample> = [
module: require('../examples/TextInput/TextInputExample.ios'),
supportsTVOS: true,
},
{
key: 'TooltipExample',
module: require('../examples/Tooltip/TooltipExample'),
supportsTVOS: true,
},
{
key: 'TouchableExample',
module: require('../examples/Touchable/TouchableExample'),
Expand Down

0 comments on commit f26243a

Please sign in to comment.