Skip to content
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

Adding animation for children of switch components #53938

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

sumo-slonik
Copy link
Contributor

@sumo-slonik sumo-slonik commented Dec 11, 2024

Explanation of Change

These PR add animations of the appearance and disappearance of elements after the switch using reanimated.

Fixed Issues

$ #53759

PROPOSAL:

Tests

  1. Go to settings
  2. Launch workflows
  3. Enter workflows
  4. Click the switches and check if the content below appears with a smooth animation
  • Verify that no errors appear in the JS console

Offline tests

Offline tests are not needed.

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android.native.mp4
Android: mWeb Chrome
web.android.mp4
iOS: Native
ios.native.mp4
iOS: mWeb Safari
web.ios.mp4
MacOS: Chrome / Safari
web.mp4
MacOS: Desktop
desktop.mp4

Copy link
Contributor

🚧 @mountiny has triggered a test build. You can view the workflow run here.

This comment has been minimized.

Copy link
Contributor

@Kicu Kicu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly ok. There is one thing with the translation keys and state that is a bit confusing. If you cannot rewrite it in any way, then at least drop a comment.
Otherwise lgtm 👍

You have a typo in name of the PR: childreans -> childrens

import type {SharedValue} from 'react-native-reanimated';
import Animated, {useAnimatedStyle, useDerivedValue, useSharedValue, withTiming} from 'react-native-reanimated';

function AccordionItem({isExpanded, children, duration = 300}: {isExpanded: SharedValue<boolean>; children: ReactNode; duration?: number}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure the file and main export are named the same:
Component is called AccordionItem but the file is Accordion/index.ts (you have a type in the name).

}));

return (
<Animated.View style={[bodyStyle, {overflow: 'hidden'}]}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Animated.View style={[bodyStyle, {overflow: 'hidden'}]}>
<Animated.View style={[bodyStyle, styles.overflowHidden]}>

where styles come from:
const styles = useThemeStyles();

@@ -26,21 +26,30 @@ type SwitchProps = {

/** Callback to fire when the switch is toggled in disabled state */
disabledAction?: () => void;

/**
* onStateChange: Callback function triggered only after the external state of the switch has successfully changed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* onStateChange: Callback function triggered only after the external state of the switch has successfully changed.
* Callback function triggered only after the external state of the switch has successfully changed.

repeating the name is not needed, as the name of prop is right below this comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this comment is a bit inaccurate.
This callback is triggered inside Switch component after the external state has changed AND the animation has finished, right?

Because if it was only after state change, then the external component could handle this itself. So I'm guessing it is important that this runs after the line:
offsetX.set(withTiming([...])...

Does this make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes after the animation of moving the circle inside the switch, but it is this callback that actually triggers in our case the animation of rolling up and unrolling children

if (!isImportMappingEnable) {
return;
}
setTranslationKey(getDisplayTypeTranslationKeys(config?.mappings?.[mappingName]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will be confusing, since assigning translation keys to state is quite uncommon.
Perhaps we could add a short 1-line comment to at least say its done for animation purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that changing the switch changes the content of the object:
config.mappings
which resulted in changing the content of the translation itself, that's why I changed the assignment here to only non-empty values, I was afraid of operating on the config logic itself so I think it's safe to leave a comment here

Copy link
Contributor

🚧 @mountiny has triggered a test build. You can view the workflow run here.

Copy link
Contributor

@sumo-slonik sumo-slonik changed the title Feature/kuba nowakowski/add animation for switch childreans Feature/kuba nowakowski/add animation for switch childrens Dec 16, 2024
Copy link
Contributor

@Kicu Kicu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 the animation is tricky but I was not able to come up with a better solution

@sumo-slonik sumo-slonik marked this pull request as ready for review December 16, 2024 08:38
@sumo-slonik sumo-slonik requested a review from a team as a code owner December 16, 2024 08:38
Copy link

melvin-bot bot commented Dec 16, 2024

@dubielzyk-expensify @thesahindia One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot removed the request for review from a team December 16, 2024 08:38
Copy link
Contributor

@blazejkustra blazejkustra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @sumo-slonik 🚀

// We are storing translation keys in the local state for animation purposes.
// Otherwise, the values change to undefined immediately after clicking, before the closing animation finishes,
// resulting in a janky animation effect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

const styles = useThemeStyles();
const offsetX = useSharedValue(isOn ? OFFSET_X.ON : OFFSET_X.OFF);
const theme = useTheme();

useEffect(() => {
offsetX.set(withTiming(isOn ? OFFSET_X.ON : OFFSET_X.OFF, {duration: 300}));
}, [isOn, offsetX]);
if (onStateChange) {
onStateChange(isOn);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use onToggle for this? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately it seems to me that it does not, because doing it in onToggle called the animation trigger at the wrong time, but I will make sure that in the final version of the code it did not become possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to remove the use of this method and it is no longer needed.

import Animated, {useAnimatedStyle, useDerivedValue, useSharedValue, withTiming} from 'react-native-reanimated';
import useThemeStyles from '@hooks/useThemeStyles';

function Accordion({isExpanded, children, duration = 300}: {isExpanded: SharedValue<boolean>; children: ReactNode; duration?: number}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract props type to a separate type above, a good rule of thumb is to always do it for complex types like this

onLayout={(e) => {
height.set(e.nativeEvent.layout.height);
}}
style={{position: 'absolute', left: 0, right: 0, top: 0}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use styling utilities here:

styles.pAbsolute, styles.t0 ...

@dubielzyk-expensify
Copy link
Contributor

The animation works well, but the padding here is wrong:
CleanShot 2024-12-17 at 14 57 59@2x

All rows go to the end and the padding should be like this:
image

@sumo-slonik
Copy link
Contributor Author

@dubielzyk-expensify good catch, I'll fix it

@sumo-slonik
Copy link
Contributor Author

@dubielzyk-expensify
Is it good now?

Screen.Recording.2024-12-17.at.10.53.55.mov

@shawnborton
Copy link
Contributor

Agree that the hint text should be included in the row hover.

In terms of your two animations Jon, I like both of them - I am guessing the version that only includes a fadeIn is probably easier to build?

@sumo-slonik
Copy link
Contributor Author

sumo-slonik commented Dec 18, 2024

From my point of view, it will take me about the same amount of time to build the first and second animation, so I will do the one that you like more.

Regarding the help text when you hover the cursor, I didn't change anything here and it is exactly as it was before. Changing this is not hard from a technical point of view, but it will affect the whole application and all the places that use MenuItem so it would probably require additional QA work.

@mountiny
Copy link
Contributor

Feel free to dk the one which will be simpler to implement

@dubielzyk-expensify
Copy link
Contributor

Regarding the help text when you hover the cursor, I didn't change anything here and it is exactly as it was before. Changing this is not hard from a technical point of view, but it will affect the whole application and all the places that use MenuItem so it would probably require additional QA work.

What's different in the markup between the one in your video vs the one you find on Settings -> Workspace -> Profile then?

From my point of view, it will take me about the same amount of time to build the first and second animation, so I will do the one that you like more.

Awesome. Let's start with the first one and we can tweak it later if we want.

@sumo-slonik
Copy link
Contributor Author

I was able to fix the hover effect, because of your example with the default currency.
I found that in the place you showed the text was shown as hint value, and in the inports as separate text this is why it was never highlighted.
I also added animations for opacity.
This is the final effect:

Screen.Recording.2024-12-19.at.17.02.24.mov

I added opacity animation however I made it as an animation between 0 and 1, on your video it looked like some opacity gradient, doing something like this will take much more time

@dannymcclain
Copy link
Contributor

I think that's looking pretty good. @Expensify/design for 👀 as well.

@shawnborton
Copy link
Contributor

This feels pretty good too.

on your video it looked like some opacity gradient, doing something like this will take much more time

Perhaps Jon was just using an easing function. Are we able to do something like ease-in-out with these animations, or is it just linear?

@@ -50,11 +52,23 @@ function SageIntacctToggleMappingsPage({route}: SageIntacctToggleMappingsPagePro

const policy = usePolicy(route.params.policyID);
const mappingName: SageIntacctMappingName = route.params.mapping;
const policyID: string = policy?.id ?? '-1';

const policyID: string = policy?.id ?? CONST.DEFAULT_POLICY_ID;
Copy link
Contributor

@blazejkustra blazejkustra Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read through contributingGuides/STYLE.md (Default value for inexistent IDs). I think we shouldn't add DEFAULT_POLICY_ID and instead use no default id at all, what do you think? @sumo-slonik

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's avoid any defaulting values for string ids!
In this case maybe you can try to use route.params.policyID - this way you won't need to handle undefined cases, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that the example in contributingGuides/STYLE.md indicates that we should have no value, but I wanted to keep the sense of the code. But I will do it as you suggest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please lets remove this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mountiny
Copy link
Contributor

@thesahindia how is it looking?

@sumo-slonik
Copy link
Contributor Author

sumo-slonik commented Dec 19, 2024

@shawnborton

Perhaps Jon was just using an easing function. Are we able to do something like ease-in-out with these animations, or is it just linear?

I can add easing and we'll determine if that's how we want to do it.

I added opacity animation however I made it as an animation between 0 and 1, on your video it looked like some opacity gradient, doing something like this will take much more time

I meant that changing the opacity on the video does not affect the whole element at the same time, I did not mean the speed of its change.
As you can see in the image which is a screenshot of the video the top is not blurred and the bottom is blurred:

image

@dubielzyk-expensify
Copy link
Contributor

Perhaps Jon was just using an easing function. Are we able to do something like ease-in-out with these animations, or is it just linear?

Yeah an ease-in-out would be good to see 👍 Otherwise looking good

@thesahindia
Copy link
Member

'Connect bank account' isn't in the center.

Screenshot 2024-12-20 at 9 51 04 AM

@thesahindia
Copy link
Member

Are we only updating Sage intacct page in this PR?

Screen.Recording.2024-12-20.at.9.56.26.AM.mov

@dubielzyk-expensify
Copy link
Contributor

Yeah, unsure what's happening here cause the whole thing is wrong. Should go edge to edge and look like this:
CleanShot 2024-12-20 at 14 45 18@2x

@thesahindia
Copy link
Member

thesahindia commented Dec 20, 2024

When you toggle the switch for an item at the bottom of the page, you have to scroll yourself to see the content at the bottom (Unrelated to this PR)

1.mov

If the switch is in the enabled state then it works fine

2.mov

Should we also work on the animation for the items in the settings list or will it be tackled separately?

Screen.Recording.2024-12-20.at.9.54.14.AM.mov

@sumo-slonik
Copy link
Contributor Author

Connect bank account' isn't in the center.

I'll fix it.

Are we only updating Sage intacct page in this PR?

I'm fixing it so it will work for the others too

@sumo-slonik
Copy link
Contributor Author

Should we also work on the animation for the items in the settings list or will it be tackled separately?

It seems to me that this should not be a part of this PR, but if you think it would be good to take care of it I will be happy to take care of it in the new one (not sure if there should be a new issue)

@dannymcclain
Copy link
Contributor

I tend to agree that we should not mess with the left hand nav right now. Let's keep this PR focused. @Expensify/design can weigh in too, but I feel like it would be better to tackle those in a separate issue.

@shawnborton
Copy link
Contributor

Yeah, makes sense to me 👍

@mountiny
Copy link
Contributor

@thesahindia how is it going on testing part?

@mountiny
Copy link
Contributor

@sumo-slonik @thesahindia Would like to confirm, what is the nest step for this pr. Can you please fix the Prettier check? Thanks!

@thesahindia
Copy link
Member

I have to finish the final testing and complete the checklist. I will do it soon.

@blazejkustra
Copy link
Contributor

I merged the newest main and fixed prettier for you @thesahindia.

@mountiny I think it is ready for testing and C+ review :)

@@ -1,7 +1,9 @@
import type {ReactNode} from 'react';
import {ReactNode, useEffect} from 'react';
Copy link
Member

@thesahindia thesahindia Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import {ReactNode, useEffect} from 'react';
import type {ReactNode} from 'react';

@@ -1,7 +1,9 @@
import type {ReactNode} from 'react';
import {ReactNode, useEffect} from 'react';
import React, {useMemo} from 'react';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import React, {useMemo} from 'react';
import React, {useMemo, useEffect} from 'react';

@@ -6440,6 +6440,8 @@ const CONST = {
},

MIGRATED_USER_WELCOME_MODAL: 'migratedUserWelcomeModal',

DEFAULT_POLICY_ID: '-1',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DEFAULT_POLICY_ID: '-1',

@@ -50,11 +52,23 @@ function SageIntacctToggleMappingsPage({route}: SageIntacctToggleMappingsPagePro

const policy = usePolicy(route.params.policyID);
const mappingName: SageIntacctMappingName = route.params.mapping;
const policyID: string = policy?.id ?? '-1';

const policyID: string = policy?.id ?? CONST.DEFAULT_POLICY_ID;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1,5 +1,7 @@
import React, {useCallback, useEffect} from 'react';
import {View} from 'react-native';
Copy link
Member

@thesahindia thesahindia Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the View import and the Text import on line 8.

It's weird, I get an error when I try to comment on other lines.
Screenshot 2024-12-24 at 4 52 15 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants