Skip to content

Add hint onPress support #1312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 20, 2021
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
5 changes: 5 additions & 0 deletions demo/src/screens/componentScreens/HintsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
});
};

onHintPressed = () => {
alert('Hint Pressed');
}

render() {
const {
showHint,
Expand Down Expand Up @@ -85,6 +89,7 @@ export default class HintsScreen extends Component<HintScreenProps, HintScreenSt
position={showBottomHint ? Hint.positions.BOTTOM : Hint.positions.TOP}
useSideTip={useSideTip}
key={targetPosition}
onPress={this.onHintPressed}
targetFrame={useTargetFrame ? targetFrame : undefined}
// borderRadius={BorderRadiuses.br40}
// edgeMargins={30}
Expand Down
6 changes: 5 additions & 1 deletion generatedTypes/components/hint/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ export interface HintProps {
*/
offset?: number;
/**
* Callback for the background press
* Callback for Hint press
*/
onPress?: () => void;
/**
* Callback for the background press
*/
onBackgroundPress?: (event: GestureResponderEvent) => void;
/**
* The hint container width
Expand Down
21 changes: 15 additions & 6 deletions src/components/hint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import View from '../view';
import Text from '../text';
import Image from '../image';
import Modal from '../modal';
import TouchableOpacity from '../touchableOpacity';

const sideTip = require('./assets/hintTipSide.png');
const middleTip = require('./assets/hintTipMiddle.png');
Expand Down Expand Up @@ -117,9 +118,13 @@ export interface HintProps {
*/
offset?: number;
/**
* Callback for the background press
* Callback for Hint press
*/
onBackgroundPress?: (event: GestureResponderEvent) => void;
onPress?: () => void;
/**
* Callback for the background press
*/
onBackgroundPress?: (event: GestureResponderEvent) => void;
/**
* The hint container width
*/
Expand Down Expand Up @@ -436,11 +441,15 @@ class Hint extends Component<HintProps, HintState> {
}

renderHint() {
const {testID} = this.props;

const {onPress, testID} = this.props;
const opacity = onPress ? 0.9 : 1.0;
const Container = onPress ? TouchableOpacity : View;

if (this.showHint) {
return (
<View
<Container
activeOpacity={opacity}
onPress={onPress}
animated
style={[
{width: this.containerWidth},
Expand All @@ -454,7 +463,7 @@ class Hint extends Component<HintProps, HintState> {
>
{this.renderHintTip()}
{this.renderContent()}
</View>
</Container>
);
}
}
Expand Down