Skip to content
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

Add new prop "interactionManagerTimeout" #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ The tooltip wraps an element _in place_ in your React Native rendering. When it
| topAdjustment | number | 0 | Value which provides additional vertical offest for the child element displayed in a tooltip. Commonly set to: `Platform.OS === 'android' ? -StatusBar.currentHeight : 0` due to an issue with React Native's measure function on Android
| horizontalAdjustment | number | 0 | Value which provides additional horizontal offest for the child element displayed in a tooltip. This is useful for adjusting the horizontal positioning of a highlighted child element if needed
| useInteractionManager | bool | false | Set this to true if you want the tooltip to wait to become visible until the callback for `InteractionManager.runAfterInteractions` is executed. Can be useful if you need to wait for navigation transitions to complete, etc. [See docs on InteractionManager here](https://facebook.github.io/react-native/docs/interactionmanager)
| interactionManagerTimeout | number | undefined | In some rare cases `InteractionManager.runAfterInteractions` is not executed. This can be useful to trigger the measurement after a maximal amount of time (in milliseconds).
| useReactNativeModal | bool| true | By default, this library uses a `<Modal>` component from React Native. If you need to disable this, and simply render an absolutely positioned full-screen view, set `useReactNativeModal={false}`. This is especially useful if you desire to render a Tooltip while you have a different `Modal` rendered.

### Style Props
Expand Down
8 changes: 7 additions & 1 deletion src/tooltip.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ declare module 'react-native-walkthrough-tooltip' {
childrenWrapperStyle?: StyleProp<ViewStyle>;

// Styles the view element that wraps the original children
parentWrapperStyle?: StyleProp<ViewStyle>
parentWrapperStyle?: StyleProp<ViewStyle>;
}

export interface TooltipProps extends Partial<TooltipStyleProps> {
Expand Down Expand Up @@ -105,6 +105,12 @@ declare module 'react-native-walkthrough-tooltip' {
*/
useInteractionManager?: boolean;

/**
* In some rare cases InteractionManager.runAfterInteractions is not executed. This can be useful
* to trigger the measurement after a maximal amount of time (in milliseconds).
*/
interactionManagerTimeout?: number;

/**
* When false, will not use a React Native Modal component to display tooltip,
* but rather an absolutely positioned view
Expand Down
13 changes: 13 additions & 0 deletions src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Tooltip extends Component {
showChildInTooltip: PropTypes.bool,
supportedOrientations: PropTypes.arrayOf(PropTypes.string),
useInteractionManager: PropTypes.bool,
interactionManagerTimeout: PropTypes.number,
useReactNativeModal: PropTypes.bool,
topAdjustment: PropTypes.number,
horizontalAdjustment: PropTypes.number,
Expand Down Expand Up @@ -294,7 +295,19 @@ class Tooltip extends Component {
if (this.interactionPromise) {
this.interactionPromise.cancel();
}

let interactionTimeout;
if (this.props.interactionManagerTimeout !== undefined) {
// Make sure doMeasurement runs, also if runAfterInteractions doesn't run (rare case)
interactionTimeout = setTimeout(() => {
doMeasurement();
}, this.props.interactionManagerTimeout);
}

this.interactionPromise = InteractionManager.runAfterInteractions(() => {
if (interactionTimeout) {
clearTimeout(interactionTimeout);
}
doMeasurement();
});
} else {
Expand Down