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 2 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
47 changes: 27 additions & 20 deletions src/components/hint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
TextStyle,
ViewStyle,
LayoutChangeEvent,
View as RNView
View as RNView,
TouchableOpacity
} from 'react-native';
import {Typography, Spacings, Colors, BorderRadiuses} from '../../style';
import {Constants} from '../../helpers';
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,25 +441,27 @@ class Hint extends Component<HintProps, HintState> {
}

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

const {onPress, testID} = this.props;
const opacity = onPress ? 0.9 : 1.0;
if (this.showHint) {
return (
<View
animated
style={[
{width: this.containerWidth},
styles.animatedContainer,
this.getHintPosition(),
this.getHintPadding(),
this.getHintAnimatedStyle()
]}
pointerEvents="box-none"
testID={testID}
>
{this.renderHintTip()}
{this.renderContent()}
</View>
<TouchableOpacity activeOpacity={opacity} onPress={onPress}>
<View
animated
style={[
{width: this.containerWidth},
styles.animatedContainer,
this.getHintPosition(),
this.getHintPadding(),
this.getHintAnimatedStyle()
]}
pointerEvents="box-none"
testID={testID}
>
{this.renderHintTip()}
{this.renderContent()}
</View>
</TouchableOpacity>
);
}
}
Expand Down