Skip to content

Commit d77465a

Browse files
authored
Add hint onPress support (#1312)
* Add hint onPress support * Container instead of wrapper component * typing autogenerated
1 parent 2b7c474 commit d77465a

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

demo/src/screens/componentScreens/HintsScreen.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
3939
});
4040
};
4141

42+
onHintPressed = () => {
43+
alert('Hint Pressed');
44+
}
45+
4246
render() {
4347
const {
4448
showHint,
@@ -85,6 +89,7 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
8589
position={showBottomHint ? Hint.positions.BOTTOM : Hint.positions.TOP}
8690
useSideTip={useSideTip}
8791
key={targetPosition}
92+
onPress={this.onHintPressed}
8893
targetFrame={useTargetFrame ? targetFrame : undefined}
8994
// borderRadius={BorderRadiuses.br40}
9095
// edgeMargins={30}

generatedTypes/components/hint/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ export interface HintProps {
8080
*/
8181
offset?: number;
8282
/**
83-
* Callback for the background press
83+
* Callback for Hint press
8484
*/
85+
onPress?: () => void;
86+
/**
87+
* Callback for the background press
88+
*/
8589
onBackgroundPress?: (event: GestureResponderEvent) => void;
8690
/**
8791
* The hint container width

src/components/hint/index.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import View from '../view';
2222
import Text from '../text';
2323
import Image from '../image';
2424
import Modal from '../modal';
25+
import TouchableOpacity from '../touchableOpacity';
2526

2627
const sideTip = require('./assets/hintTipSide.png');
2728
const middleTip = require('./assets/hintTipMiddle.png');
@@ -117,9 +118,13 @@ export interface HintProps {
117118
*/
118119
offset?: number;
119120
/**
120-
* Callback for the background press
121+
* Callback for Hint press
121122
*/
122-
onBackgroundPress?: (event: GestureResponderEvent) => void;
123+
onPress?: () => void;
124+
/**
125+
* Callback for the background press
126+
*/
127+
onBackgroundPress?: (event: GestureResponderEvent) => void;
123128
/**
124129
* The hint container width
125130
*/
@@ -437,11 +442,15 @@ class Hint extends Component<HintProps, HintState> {
437442
}
438443

439444
renderHint() {
440-
const {testID} = this.props;
441-
445+
const {onPress, testID} = this.props;
446+
const opacity = onPress ? 0.9 : 1.0;
447+
const Container = onPress ? TouchableOpacity : View;
448+
442449
if (this.showHint) {
443450
return (
444-
<View
451+
<Container
452+
activeOpacity={opacity}
453+
onPress={onPress}
445454
animated
446455
style={[
447456
{width: this.containerWidth},
@@ -455,7 +464,7 @@ class Hint extends Component<HintProps, HintState> {
455464
>
456465
{this.renderHintTip()}
457466
{this.renderContent()}
458-
</View>
467+
</Container>
459468
);
460469
}
461470
}

0 commit comments

Comments
 (0)