Skip to content

Commit

Permalink
feat(Touchable): change hook params with new Bara API
Browse files Browse the repository at this point in the history
  • Loading branch information
nampdn committed Apr 26, 2019
1 parent 79a23dd commit cea652b
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/lib/exports/Touchable/hook.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import { TouchableEventFilter } from './event'
import {
ActionPipe,
BaraEventPayload,
ConditionPipe,
createPipe,
useAction,
useCondition,
useEvent,
useTrigger,
} from 'bara'

import { BaraReactTouchable, useTouchablePressEvent } from './event'
import { TouchablePressCallback, useTouchablePressTrigger } from './trigger'

export function whenTouchablePress(
eventFilter: TouchableEventFilter,
callback: TouchablePressCallback,
) {
return useTouchablePressTrigger(eventFilter, callback)
export const whenTouchablePress = (
...conditions: Array<ConditionPipe<BaraReactTouchable>>
) => (...actions: Array<ActionPipe<BaraReactTouchable>>) => {
const piper = (
data: BaraReactTouchable,
payload: BaraEventPayload<BaraReactTouchable>,
) => {
createPipe(data, payload)(...(conditions as any))(...actions)
}
useTrigger<BaraReactTouchable>(() => {
const event = useTouchablePressEvent()
const action = useAction(piper)
return { event, action }
})
}

0 comments on commit cea652b

Please sign in to comment.