-
Notifications
You must be signed in to change notification settings - Fork 739
Dialog - useHiddenLocation, added reduce motion listener for testing on Android. #3739
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9fb9c47
feat(accessibility): add reduce motion support for Android in useHidd…
adids1221 1c6d6eb
Refactor addEventListener to isReduceMotionEnabled
adids1221 c658bbd
Merge branch 'master' into fix/Diloag_reductionMouvement_state_fix
adids1221 fd95b15
Merge branch 'master' into fix/Diloag_reductionMouvement_state_fix
adids1221 75fd0d2
Merge branch 'fix/Diloag_reductionMouvement_state_fix' of github.com:…
adids1221 01320e1
useHiddenLocation revert, remove test
adids1221 62f2b6b
update: added a new property `isReduceMotionEnabled` to the accessib…
adids1221 635cca9
update: mock in jest-setup, fix animation in Dialog, fix test
adids1221 bf01f1f
remove comments
adids1221 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,44 @@ | ||
import {renderHook, act} from '@testing-library/react-hooks'; | ||
import {AccessibilityInfo} from 'react-native'; | ||
import {Constants} from '../../../commons/new'; | ||
import useHiddenLocation from '../useHiddenLocation'; | ||
|
||
describe('useHiddenLocation', () => { | ||
const defaultExpectedLocation = { | ||
up: -Constants.windowHeight, | ||
down: Constants.windowHeight, | ||
left: -Constants.screenWidth, | ||
right: Constants.screenWidth, | ||
wasMeasured: true | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.spyOn(AccessibilityInfo, 'isReduceMotionEnabled').mockResolvedValue(false); | ||
(AccessibilityInfo.addEventListener as jest.Mock) = jest.fn().mockImplementation((_event, _callback) => { | ||
return { | ||
remove: jest.fn() | ||
}; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return default positions when no layout is provided', () => { | ||
const {result} = renderHook(() => useHiddenLocation()); | ||
expect(result.current.hiddenLocation).toEqual(defaultExpectedLocation); | ||
}); | ||
|
||
it('should return defaultHiddenLocation on Android when reduce motion is enabled', async () => { | ||
const originalIsAndroid = Constants.isAndroid; | ||
Constants.isAndroid = true; | ||
jest.spyOn(AccessibilityInfo, 'isReduceMotionEnabled').mockResolvedValue(true); | ||
const {result} = renderHook(() => useHiddenLocation()); | ||
await act(async () => { | ||
await Promise.resolve(); | ||
}); | ||
expect(result.current.hiddenLocation).toEqual(defaultExpectedLocation); | ||
Constants.isAndroid = originalIsAndroid; | ||
}); | ||
}); |
This file contains hidden or 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import {isEqual} from 'lodash'; | ||
import {useCallback, useRef, useState, RefCallback} from 'react'; | ||
import {View, LayoutChangeEvent, LayoutRectangle} from 'react-native'; | ||
import {useCallback, useRef, useState, RefCallback, useEffect} from 'react'; | ||
import {View, LayoutChangeEvent, LayoutRectangle, AccessibilityInfo} from 'react-native'; | ||
import {Constants} from '../../commons/new'; | ||
import {PanningDirectionsEnum} from '../panView'; | ||
|
||
|
@@ -13,14 +13,32 @@ export interface HiddenLocation extends HiddenLocationRecord { | |
// Adding this for headless tests that are not triggering onLayout | ||
const wasMeasuredDefaultValue = global._UILIB_TESTING ?? false; | ||
|
||
const defaultHiddenLocation = { | ||
up: -Constants.windowHeight, | ||
down: Constants.windowHeight, | ||
left: -Constants.screenWidth, | ||
right: Constants.screenWidth, | ||
wasMeasured: wasMeasuredDefaultValue | ||
}; | ||
|
||
export default function useHiddenLocation<T extends View>() { | ||
const [reduceMotionEnabled, setReduceMotionEnabled] = useState(false); | ||
|
||
useEffect(() => { | ||
AccessibilityInfo.isReduceMotionEnabled().then(setReduceMotionEnabled); | ||
}, []); | ||
|
||
const getHiddenLocation = ({ | ||
x = 0, | ||
y = 0, | ||
width = Constants.screenWidth, | ||
height = Constants.windowHeight, | ||
wasMeasured = wasMeasuredDefaultValue | ||
}): HiddenLocation => { | ||
if (Constants.isAndroid && reduceMotionEnabled) { | ||
return defaultHiddenLocation; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this just |
||
} | ||
|
||
return { | ||
up: -y - height, | ||
down: Constants.windowHeight - y, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look in
Constants
->accessibility
is set with a promise, we can probably add the info there IMO.