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

Added onZonePress #3

Open
wants to merge 2 commits 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
2 changes: 2 additions & 0 deletions src/components/ConnectedStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface Props {
borderRadius?: number
keepTooltipPosition?: boolean
tooltipBottomOffset?: number
isLastStep: boolean
onZonePress?: () => void
}

export class ConnectedStep extends React.Component<Props> {
Expand Down
18 changes: 10 additions & 8 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ export class Modal extends React.Component<ModalProps, State> {
verticalPosition === 'bottom'
? tooltip.top
: obj.top -
MARGIN -
135 -
(this.props.currentStep!.tooltipBottomOffset || 0)
MARGIN -
135 -
(this.props.currentStep?.tooltipBottomOffset || 0)
const translateAnim = Animated.timing(this.state.tooltipTranslateY, {
toValue,
duration,
Expand Down Expand Up @@ -274,6 +274,8 @@ export class Modal extends React.Component<ModalProps, State> {
borderRadius={this.props.borderRadius}
dismissOnPress={this.props.dismissOnPress}
stop={this.props.stop}
isLastStep={this.props.isLastStep}
handleNext={this.props.next}
/>
)

Expand Down Expand Up @@ -313,11 +315,13 @@ export class Modal extends React.Component<ModalProps, State> {
}

renderNonInteractionPlaceholder() {
return this.props.preventOutsideInteraction ? <View
style={[StyleSheet.absoluteFill, styles.nonInteractionPlaceholder]} /> : null
return this.props.preventOutsideInteraction ? (
<View
style={[StyleSheet.absoluteFill, styles.nonInteractionPlaceholder]}
/>
) : null
}


render() {
const containerVisible = this.state.containerVisible || this.props.visible
const contentVisible = this.state.layout && containerVisible
Expand All @@ -334,8 +338,6 @@ export class Modal extends React.Component<ModalProps, State> {
onLayout={this.handleLayoutChange}
pointerEvents='box-none'
>


{contentVisible && (
<>
{this.renderMask()}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface Props {
keepTooltipPosition?: boolean
tooltipBottomOffset?: number
borderRadiusObject?: BorderRadiusObject
isLastStep: boolean
onZonePress?: () => void
}

export const Step = (props: Props) => {
Expand Down
46 changes: 39 additions & 7 deletions src/components/SvgMask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
LayoutChangeEvent,
Platform,
StyleProp,
View,
ViewStyle,
TouchableWithoutFeedback,
ScaledSize,
GestureResponderEvent,
Pressable,
} from 'react-native'
import Svg, { PathProps } from 'react-native-svg'
import { IStep, ValueXY } from '../types'
Expand All @@ -28,6 +28,8 @@ interface Props {
currentStep?: IStep
easing: (value: number) => number
stop: () => void
handleNext: () => void
isLastStep: boolean
}

interface State {
Expand Down Expand Up @@ -185,15 +187,45 @@ export class SvgMask extends Component<Props, State> {
if (!this.state.canvasSize) {
return null
}
const { dismissOnPress, stop } = this.props
const Wrapper: any = dismissOnPress ? TouchableWithoutFeedback : View

const {
dismissOnPress,
stop,
position,
size,
currentStep,
isLastStep,
handleNext,
} = this.props
const onZonePress = (e: GestureResponderEvent) => {
const { locationX, locationY } = e.nativeEvent
if (
locationX >= position.x &&
locationX <= position.x + size.x &&
locationY >= position.y &&
locationY <= position.y + size.y
) {
if (currentStep && currentStep.onZonePress) {
currentStep.onZonePress()
return
}
if (isLastStep) {
stop()
} else {
handleNext()
}
} else if (dismissOnPress) {
stop()
return
}
}

return (
<Wrapper
<Pressable
style={this.props.style}
onLayout={this.handleLayout}
pointerEvents='none'
onPress={dismissOnPress ? stop : undefined}
onPress={onZonePress}
>
<Svg
pointerEvents='none'
Expand All @@ -209,7 +241,7 @@ export class SvgMask extends Component<Props, State> {
opacity={this.state.opacity as any}
/>
</Svg>
</Wrapper>
</Pressable>
)
}
}
6 changes: 6 additions & 0 deletions src/components/TourGuideZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface TourGuideZoneProps {
keepTooltipPosition?: boolean
tooltipBottomOffset?: number
borderRadiusObject?: BorderRadiusObject
onZonePress?: () => void
isLastStep: boolean
}

export const TourGuideZone = ({
Expand All @@ -32,6 +34,8 @@ export const TourGuideZone = ({
keepTooltipPosition,
tooltipBottomOffset,
borderRadiusObject,
onZonePress,
isLastStep,
}: TourGuideZoneProps) => {
if (!isTourGuide) {
return <>{children}</>
Expand All @@ -50,6 +54,8 @@ export const TourGuideZone = ({
keepTooltipPosition,
tooltipBottomOffset,
borderRadiusObject,
onZonePress,
isLastStep,
}}
>
<Wrapper {...{ style }}>{children}</Wrapper>
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface IStep {
keepTooltipPosition?: boolean
tooltipBottomOffset?: number
borderRadiusObject?: BorderRadiusObject
isLastStep: boolean
onZonePress?: () => void
}
export interface StepObject {
[key: string]: IStep
Expand Down