Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Libraries/Components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,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 @@ -211,6 +215,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 @@ -261,6 +266,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 @@ -694,6 +694,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://facebook.github.io/react-native/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 @@ -196,6 +196,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