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

WRQ-24303: Fix marqueeDecorator and marqueeController to start animation properly when content changed #3247

Merged
merged 10 commits into from
Jun 28, 2024
6 changes: 6 additions & 0 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The following is a curated list of changes in the Enact ui module, newest changes on the top.

## [unreleased]

### Fixed

- `ui/Marquee.MarqueeDecorator` to start animation properly when synchronized by `ui/Marquee.MarqueeController` and text changed

## [4.9.0-beta.1] - 2024-06-17

No significant changes.
Expand Down
7 changes: 4 additions & 3 deletions packages/ui/Marquee/MarqueeDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
if (this.context && this.context.register) {
this.sync = true;
this.context.register(this, {
restartAnimation: this.restartAnimation,
start: this.start,
stop: this.stop
});
Expand Down Expand Up @@ -412,7 +413,7 @@
);

this.invalidateMetrics();
this.cancelAnimation();
this.cancelAnimation(forceRestartMarquee);
if (forceRestartMarquee && marqueeOn === 'focus') {
this.resetAnimation();
}
Expand Down Expand Up @@ -795,9 +796,9 @@
*
* @returns {undefined}
*/
cancelAnimation = () => {
cancelAnimation = (retryStartingAnimation = false) => {
if (this.sync) {
this.context.cancel(this);
this.context.cancel(retryStartingAnimation);

Check warning on line 801 in packages/ui/Marquee/MarqueeDecorator.js

View check run for this annotation

Codecov / codecov/patch

packages/ui/Marquee/MarqueeDecorator.js#L801

Added line #L801 was not covered by tests
return;
}

Expand Down
23 changes: 13 additions & 10 deletions packages/ui/Marquee/useMarqueeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Invokes the `action` handler for each synchronized component except the invoking
* `component`.
*
* @param {String} action `'start'` or `'stop'`
* @param {String} action `'start'`, `'stop'`, or `'restartAnimation'`
* @param {Object} component A previously registered component
*
* @returns {undefined}
Expand Down Expand Up @@ -102,22 +102,25 @@
}, false);
}, []);

const doCancel = useCallback(() => {
const doCancel = useCallback((retryStartingAnimation) => {
if (mutableRef.current.isHovered || mutableRef.current.isFocused) {
return;
}
markAll(STATE.inactive);
dispatch('stop');
if (retryStartingAnimation) {
dispatch('restartAnimation');

Check warning on line 112 in packages/ui/Marquee/useMarqueeController.js

View check run for this annotation

Codecov / codecov/patch

packages/ui/Marquee/useMarqueeController.js#L112

Added line #L112 was not covered by tests
}
}, [dispatch, markAll]);

const cancelJob = useMemo(() => new Job(() => doCancel(), 30), [doCancel]);
const cancelJob = useMemo(() => new Job((retryStartingAnimation = false) => doCancel(retryStartingAnimation), 30), [doCancel]);

/*
* Registers `component` with a set of handlers for `start` and `stop`.
* Registers `component` with a set of handlers for `start`, `stop`, and `restartAnimation`.
*
* @param {Object} component A component, typically a React component instance, on
* which handlers will be dispatched.
* @param {Object} handlers An object containing `start` and `stop` functions
* @param {Object} handlers An object containing `start`, `stop`, and `restartAnimation` functions
*
* @returns {undefined}
*/
Expand Down Expand Up @@ -161,7 +164,7 @@
*
* @param {Object} component A previously registered component
*
* @returns {undefined}f
* @returns {undefined}
*/
const handleStart = useCallback((component) => {
cancelJob.stop();
Expand All @@ -174,13 +177,13 @@
/*
* Handler for the `cancel` context function
*
* @param {Object} component A previously registered component
* @param {Boolean} retryStartingAnimation If true, `restartAnimation` called after `cancelJob` completes
*
MikyungKim marked this conversation as resolved.
Show resolved Hide resolved
* @returns {undefined}
*/
const handleCancel = useCallback(() => {
const handleCancel = useCallback((retryStartingAnimation) => {
if (anyRunning()) {
cancelJob.start();
cancelJob.start(retryStartingAnimation);

Check warning on line 186 in packages/ui/Marquee/useMarqueeController.js

View check run for this annotation

Codecov / codecov/patch

packages/ui/Marquee/useMarqueeController.js#L186

Added line #L186 was not covered by tests
}
}, [anyRunning, cancelJob]);

Expand All @@ -193,7 +196,7 @@
*/
const handleComplete = useCallback((component) => {
const complete = markReady(component);
if (complete) {
if (complete && !component.contentFits) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can have this change in develop branch, but we need to discuss when we make a change to deployed one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I agree.

markAll(STATE.ready);
dispatch('start');
}
Expand Down
Loading