Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(Animation): add logic for mount/remove children #2115

Merged
merged 29 commits into from
Jan 27, 2020

Conversation

mnajdova
Copy link
Contributor

@mnajdova mnajdova commented Nov 15, 2019

This PR adds the option on the Animation component, to wait with the mounting of the component until it is visible, as well as remove the dom element if the element is hidden.

For this, the react-transition-group dependency was added, and the Transition component is used behind the scenes from the Animation component. The API exposed is partially the Transition's API.

There are example usages in the changes.

BREAKING CHANGE
Other change is that, the Animation component is not rendering the additional div anymore, it is rendering only the children.

onExiting={onExiting}
onExited={onExited}
>
{state => result}
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 am currently not using the state, as in the usage I am changing the animation. We don't have the children as function concept anywhere else so far, so I didn't add it for the Animation component. (it would be easy to migrate if we decide in the future!)

Copy link
Collaborator

@codepretty codepretty Nov 19, 2019

Choose a reason for hiding this comment

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

Does this work for adding/removing table items within the Table component or tree items within Tree?

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 should work, if not, we can Implement the AnimationGroup component in a similar way of how the TransitionGroup (https://reactcommunity.org/react-transition-group/transition-group) component is implemented from the same library). But, to be honest, I would try to avoid adding different APIs and try to implement it with this API

@@ -27,6 +27,7 @@ export interface Conformant {
exportedAtTopLevel?: boolean
rendersPortal?: boolean
wrapperComponent?: React.ReactType
handlesAsProp?: boolean
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As the Animation is not rendering root element, but only copies the children, we don't have the "as" prop there.

@@ -26,7 +26,8 @@
"popper.js": "^1.15.0",
"prop-types": "^15.7.2",
"react-fela": "^10.6.1",
"react-is": "^16.6.3"
"react-is": "^16.6.3",
"react-transition-group": "^4.3.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New dependency added

@DustyTheBot
Copy link
Collaborator

DustyTheBot commented Nov 18, 2019

Warnings
⚠️ Package (or peer) dependencies changed. Make sure you have approval before merging!

Changed dependencies are detected.

Changed dependencies in packages/react/package.json

package before after
react-transition-group - ^4.3.0

Perf comparison

Status Scenario Fluent TPI Fabric TPI Ratio Iterations Ticks
🔧 Avatar.Fluent 0.56 0.4 1.4:1 2000 1111
🔧 Button.Fluent 1.26 0.17 7.41:1 1000 1258
🔧 Checkbox.Fluent 1.4 0.3 4.67:1 1000 1397
🔧 Dialog.Fluent 0.32 0.18 1.78:1 5000 1602
🔧 Dropdown.Fluent 3.67 0.53 6.92:1 1000 3665
🔧 Icon.Fluent 0.3 0.04 7.5:1 5000 1515
🔧 Image.Fluent 0.11 0.09 1.22:1 5000 559
🔧 Slider.Fluent 2.25 0.35 6.43:1 1000 2246
🦄 Text.Fluent 0.07 0.19 0.37:1 5000 330
🦄 Tooltip.Fluent 0.36 19.54 0.02:1 5000 1791

🔧 Needs work     🎯 On target     🦄 Amazing

Generated by 🚫 dangerJS

unmountOnExit?: boolean

/** The duration of the transition, in milliseconds. */
timeout?: number | { enter?: number; exit?: number; appear?: number }
Copy link
Collaborator

Choose a reason for hiding this comment

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

based on your comment, should timeout actually be named duration?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, nevermind. i see that it is what it's called in react-transition-group... https://reactcommunity.org/react-transition-group/transition#Transition-prop-timeout

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this two are different concepts (duration is the css animationDuraion), and this is timeout for removing the elements. Maybe I should come up with a better name...

@mnajdova mnajdova changed the title [WIP] feat(Animation): add logic for mount/remove children feat(Animation): add logic for mount/remove children Nov 28, 2019
@ecraig12345 ecraig12345 mentioned this pull request Dec 6, 2019
@ecraig12345
Copy link
Member

Hi, just a heads up that I made a change #2153 renaming all lib folders to utils. So the changes to lib files in this PR will need to be moved to the new location.

# Conflicts:
#	CHANGELOG.md
#	packages/react/package.json
#	packages/react/src/components/Animation/Animation.tsx
#	packages/react/src/themes/teams/components/Animation/animationStyles.ts
# Conflicts:
#	CHANGELOG.md
#	packages/react/package.json
#	packages/react/src/components/Animation/Animation.tsx
#	packages/react/src/themes/teams/components/Animation/animationStyles.ts
-remove craft
-updated snapshots
CHANGELOG.md Outdated Show resolved Hide resolved
onEntered?: (node: HTMLElement, isAppearing: boolean) => void

/** Callback fired before the "exiting" status is applied. */
onExit?: (node: HTMLElement) => void
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
onExit?: (node: HTMLElement) => void
onExit?: () => void

Do we want to expose node there? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the API from the Transition component itself, I would rather not change anything for now...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But maybe we should return here null as first argument for the event, and the node afterwards, to be consistent with the other callbacks. What do you think?

Maybe I am over-complicating, but let me know what you think @layershifter

@mnajdova mnajdova merged commit f16bf46 into master Jan 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants