-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct the way how disabling touchable is handled (#3803)
- Loading branch information
1 parent
9337d33
commit 0ed4dc4
Showing
9 changed files
with
162 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import hasTouchHandler from '../hasTouchHandler'; | ||
|
||
describe('hasTouchHandler', () => { | ||
it.each([ | ||
[{ onPress: jest.fn() }], | ||
[{ onLongPress: jest.fn() }], | ||
[{ onPressIn: jest.fn() }], | ||
[{ onPressOut: jest.fn() }], | ||
])( | ||
'should return true if touchableEventObject contains touchable event %p', | ||
(touchableEventObject) => { | ||
const result = hasTouchHandler(touchableEventObject); | ||
|
||
expect(result).toBe(true); | ||
} | ||
); | ||
|
||
it('should return true if two touchable events are passed, but one is undefined', () => { | ||
const result = hasTouchHandler({ | ||
onPress: jest.fn(), | ||
onLongPress: undefined, | ||
}); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return false if touchable events are undefined', () => { | ||
const result = hasTouchHandler({ | ||
onPress: undefined, | ||
onLongPress: undefined, | ||
onPressIn: undefined, | ||
onPressOut: undefined, | ||
}); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { GestureResponderEvent } from 'react-native'; | ||
|
||
const touchableEvents = [ | ||
'onPress', | ||
'onLongPress', | ||
'onPressIn', | ||
'onPressOut', | ||
] as const; | ||
|
||
type TouchableEventObject = Partial< | ||
Record<typeof touchableEvents[number], (event: GestureResponderEvent) => void> | ||
>; | ||
|
||
export default function hasTouchHandler( | ||
touchableEventObject: TouchableEventObject | ||
) { | ||
return touchableEvents.some((event) => { | ||
return Boolean(touchableEventObject[event]); | ||
}); | ||
} |