-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(money): tilt-driven parallax on Money onboarding card (MUSD-1048) #32892
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fb8f8e6
feat(money): tilt-driven parallax on Money onboarding card (MUSD-1048)
Kureev a1b2acb
refactor(money): drop parallax animation feature flag
Kureev 89aebb7
feat(money): wire parallax into the Get MetaMask card onboarding step
Kureev d40a592
fix(money): address parallax review feedback and fix unit tests
Kureev 441dd4f
chore(money): register earnMoneyParallaxAnimationEnabled feature flag
Kureev 7df7e3c
refactor(money): address parallax review feedback
Kureev 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
Binary file not shown.
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
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
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
10 changes: 10 additions & 0 deletions
10
...nts/UI/Money/components/MoneyNextBestActionParallax/MoneyNextBestActionParallax.styles.ts
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,10 @@ | ||
| import { StyleSheet } from 'react-native'; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| media: { | ||
| width: '100%', | ||
| height: '100%', | ||
| }, | ||
| }); | ||
|
|
||
| export default styles; |
220 changes: 220 additions & 0 deletions
220
...ents/UI/Money/components/MoneyNextBestActionParallax/MoneyNextBestActionParallax.test.tsx
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,220 @@ | ||
| import React from 'react'; | ||
| import { render, act } from '@testing-library/react-native'; | ||
| import MoneyNextBestActionParallax from './MoneyNextBestActionParallax'; | ||
| import { MoneyNextBestActionParallaxTestIds } from './MoneyNextBestActionParallax.testIds'; | ||
| import { useReduceMotion } from '../../hooks/useReduceMotion'; | ||
| import { useDeviceOrientation } from '../../hooks/useDeviceOrientation'; | ||
| import fallbackImage from '../../../../../images/money-onboarding-stepper-step-1.png'; | ||
|
|
||
| const mockSetXValue = jest.fn(); | ||
| const mockSetYValue = jest.fn(); | ||
| const mockRefCallback = jest.fn(); | ||
| const mockRiveInstance = {}; | ||
| const mockOnErrorRef: { current?: (error: { message: string }) => void } = {}; | ||
| const mockRiveProps: { current?: { artboardName?: string } } = {}; | ||
|
|
||
| jest.mock('rive-react-native', () => { | ||
| const ReactActual = jest.requireActual('react'); | ||
| const { View: RNView } = jest.requireActual('react-native'); | ||
| return { | ||
| __esModule: true, | ||
| AutoBind: jest.fn(() => ({})), | ||
| Fit: { Contain: 'contain' }, | ||
| useRive: () => [mockRefCallback, mockRiveInstance], | ||
| useRiveNumber: (_instance: unknown, path: string) => [ | ||
| undefined, | ||
| path === 'xValue' ? mockSetXValue : mockSetYValue, | ||
| ], | ||
| default: (props: { | ||
| testID?: string; | ||
| artboardName?: string; | ||
| onError?: (error: { message: string }) => void; | ||
| }) => { | ||
| mockOnErrorRef.current = props.onError; | ||
| mockRiveProps.current = { artboardName: props.artboardName }; | ||
| return ReactActual.createElement(RNView, { testID: props.testID }); | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| const mockUseSelector = jest.fn(); | ||
| jest.mock('react-redux', () => ({ | ||
| useSelector: (selector: unknown) => mockUseSelector(selector), | ||
| })); | ||
|
|
||
| jest.mock('../../hooks/useReduceMotion', () => ({ | ||
| useReduceMotion: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../../hooks/useDeviceOrientation', () => ({ | ||
| useDeviceOrientation: jest.fn(), | ||
| })); | ||
|
|
||
| const mockUseReduceMotion = useReduceMotion as jest.Mock; | ||
| const mockUseDeviceOrientation = useDeviceOrientation as jest.Mock; | ||
|
|
||
| describe('MoneyNextBestActionParallax', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockOnErrorRef.current = undefined; | ||
| mockRiveProps.current = undefined; | ||
| mockUseSelector.mockReturnValue(true); | ||
| mockUseReduceMotion.mockReturnValue(false); | ||
| }); | ||
|
|
||
| it('renders the Rive animation when enabled and reduce motion is off', () => { | ||
| const { getByTestId, queryByTestId } = render( | ||
| <MoneyNextBestActionParallax | ||
| artboardName="Parallax Block 1" | ||
| fallbackImage={fallbackImage} | ||
| />, | ||
| ); | ||
|
|
||
| expect( | ||
| getByTestId(MoneyNextBestActionParallaxTestIds.RIVE), | ||
| ).toBeOnTheScreen(); | ||
| expect( | ||
| queryByTestId(MoneyNextBestActionParallaxTestIds.STATIC_IMAGE), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders the gradient background behind the Rive when animating', () => { | ||
| const { getByTestId } = render( | ||
| <MoneyNextBestActionParallax | ||
| artboardName="Parallax Block 1" | ||
| fallbackImage={fallbackImage} | ||
| />, | ||
| ); | ||
|
|
||
| expect( | ||
| getByTestId(MoneyNextBestActionParallaxTestIds.BACKGROUND), | ||
| ).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('passes the given artboard name through to Rive', () => { | ||
| render( | ||
| <MoneyNextBestActionParallax | ||
| artboardName="Parallax Block 2" | ||
| fallbackImage={fallbackImage} | ||
| />, | ||
| ); | ||
|
|
||
| expect(mockRiveProps.current?.artboardName).toBe('Parallax Block 2'); | ||
| }); | ||
|
|
||
| it('does not render the gradient background behind the fallback image', () => { | ||
| mockUseReduceMotion.mockReturnValue(true); | ||
|
|
||
| const { queryByTestId } = render( | ||
| <MoneyNextBestActionParallax | ||
| artboardName="Parallax Block 1" | ||
| fallbackImage={fallbackImage} | ||
| />, | ||
| ); | ||
|
|
||
| expect( | ||
| queryByTestId(MoneyNextBestActionParallaxTestIds.BACKGROUND), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders the fallback image when the feature flag is disabled', () => { | ||
| mockUseSelector.mockReturnValue(false); | ||
|
|
||
| const { getByTestId, queryByTestId } = render( | ||
| <MoneyNextBestActionParallax | ||
| artboardName="Parallax Block 1" | ||
| fallbackImage={fallbackImage} | ||
| />, | ||
| ); | ||
|
|
||
| expect( | ||
| getByTestId(MoneyNextBestActionParallaxTestIds.STATIC_IMAGE), | ||
| ).toBeOnTheScreen(); | ||
| expect(queryByTestId(MoneyNextBestActionParallaxTestIds.RIVE)).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders the fallback image (with the provided source) when reduce motion is enabled', () => { | ||
| mockUseReduceMotion.mockReturnValue(true); | ||
|
|
||
| const { getByTestId, queryByTestId } = render( | ||
| <MoneyNextBestActionParallax | ||
| artboardName="Parallax Block 1" | ||
| fallbackImage={fallbackImage} | ||
| />, | ||
| ); | ||
|
|
||
| expect( | ||
| getByTestId(MoneyNextBestActionParallaxTestIds.STATIC_IMAGE).props.source, | ||
| ).toBe(fallbackImage); | ||
| expect(queryByTestId(MoneyNextBestActionParallaxTestIds.RIVE)).toBeNull(); | ||
| }); | ||
|
|
||
| it('enables the device tilt callback when animating', () => { | ||
| render( | ||
| <MoneyNextBestActionParallax | ||
| artboardName="Parallax Block 1" | ||
| fallbackImage={fallbackImage} | ||
| />, | ||
| ); | ||
|
|
||
| expect(mockUseDeviceOrientation).toHaveBeenCalledWith( | ||
| expect.any(Function), | ||
| { | ||
| enabled: true, | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| it('disables the device tilt callback when not animating', () => { | ||
| mockUseReduceMotion.mockReturnValue(true); | ||
|
|
||
| render( | ||
| <MoneyNextBestActionParallax | ||
| artboardName="Parallax Block 1" | ||
| fallbackImage={fallbackImage} | ||
| />, | ||
| ); | ||
|
|
||
| expect(mockUseDeviceOrientation).toHaveBeenCalledWith( | ||
| expect.any(Function), | ||
| { | ||
| enabled: false, | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| it('drives the bound Rive number properties from mapped tilt values', () => { | ||
| render( | ||
| <MoneyNextBestActionParallax | ||
| artboardName="Parallax Block 1" | ||
| fallbackImage={fallbackImage} | ||
| />, | ||
| ); | ||
|
|
||
| const applyTilt = mockUseDeviceOrientation.mock.calls[0][0] as ( | ||
| x: number, | ||
| y: number, | ||
| ) => void; | ||
|
|
||
| act(() => applyTilt(0.5, -0.5)); | ||
|
|
||
| expect(mockSetXValue).toHaveBeenCalledWith(75); | ||
| expect(mockSetYValue).toHaveBeenCalledWith(25); | ||
| }); | ||
|
|
||
| it('falls back to the static image when Rive reports an error', () => { | ||
| const { getByTestId, queryByTestId } = render( | ||
| <MoneyNextBestActionParallax | ||
| artboardName="Parallax Block 1" | ||
| fallbackImage={fallbackImage} | ||
| />, | ||
| ); | ||
|
|
||
| act(() => mockOnErrorRef.current?.({ message: 'boom' })); | ||
|
|
||
| expect( | ||
| getByTestId(MoneyNextBestActionParallaxTestIds.STATIC_IMAGE), | ||
| ).toBeOnTheScreen(); | ||
| expect(queryByTestId(MoneyNextBestActionParallaxTestIds.RIVE)).toBeNull(); | ||
| }); | ||
| }); |
6 changes: 6 additions & 0 deletions
6
...ts/UI/Money/components/MoneyNextBestActionParallax/MoneyNextBestActionParallax.testIds.ts
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,6 @@ | ||
| export const MoneyNextBestActionParallaxTestIds = { | ||
| CONTAINER: 'money-next-best-action-parallax-container', | ||
| RIVE: 'money-next-best-action-parallax-rive', | ||
| BACKGROUND: 'money-next-best-action-parallax-background', | ||
| STATIC_IMAGE: 'money-next-best-action-parallax-static-image', | ||
| } as const; |
Oops, something went wrong.
Oops, something went wrong.
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.
I don't see the media being rendered in the StepperCard. It's only being used as a condition. Is that intended?
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.
StepperCard.tsx:60
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.
not as a condition, but as a
??, so ifmediaexists, it will use it, otherwise fallback to Image