Skip to content

Commit

Permalink
feat(Touchable): add onPressIn, onPressOut, onLongPress
Browse files Browse the repository at this point in the history
  • Loading branch information
nampdn committed Apr 25, 2019
1 parent 8c23f3c commit 6d14a05
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
53 changes: 43 additions & 10 deletions src/lib/exports/Touchable/Touchable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,66 @@ export const TouchableBase = React.forwardRef(
{
TouchableComponent,
onPress: _onPress,
onPressIn: _onPressIn,
onPressOut: _onPressOut,
onLongPress: _onLongPress,
name,
...props
}: TouchableBaseProps,
ref: any,
) => {
const context = useBaraContext()

const onPress: typeof _onPress = e => {
context.components.touchable.onPress({ name, ...props })
context.components.touchable.onPress({ name, ...props, event: e })
if (_onPress) {
_onPress(e)
}
}
return <TouchableComponent {...props} ref={ref} onPress={onPress} />
},
)

export const Touchable = React.forwardRef(
(props: TouchableProps, ref: any) => {
const onPressIn: typeof _onPressIn = e => {
context.components.touchable.onPressIn({ name, ...props, event: e })
if (_onPressIn) {
_onPressIn(e)
}
}

const onPressOut: typeof _onPressOut = e => {
context.components.touchable.onPressOut({ name, ...props, event: e })
if (_onPressOut) {
_onPressOut(e)
}
}

const onLongPress: typeof _onLongPress = e => {
context.components.touchable.onLongPress({ name, ...props, event: e })
if (_onLongPress) {
_onLongPress(e)
}
}

return (
<TouchableBase
ref={ref}
TouchableComponent={TouchableOpacity}
activeOpacity={1}
<TouchableComponent
{...props}
ref={ref}
onPress={onPress}
onPressIn={onPressIn}
onPressOut={onPressOut}
onLongPress={onLongPress}
/>
)
},
)

export const Touchable = React.forwardRef((props: TouchableProps, ref: any) => {
return (
<TouchableBase
ref={ref}
TouchableComponent={TouchableOpacity}
activeOpacity={1}
{...props}
/>
)
})

export type Touchable = TouchableOpacity
1 change: 1 addition & 0 deletions src/lib/exports/Touchable/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface BaraReactTouchable {
className?: string
ref?: any
id?: string
event?: any
}

export const ON_TOUCHABLE_PRESS = createEventType('ON_TOUCHABLE_PRESSED')
Expand Down

0 comments on commit 6d14a05

Please sign in to comment.