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

Fix: Allow tooltips to follow animations #583

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions js/views/TooltipItemView.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ export default class TooltipItemView extends Backbone.View {
this.parent = parent;
this.$target.attr('aria-describedby', `tooltip-${this.model.get('_id')}`);
this.listenTo(this.model, 'change', this.changed);
this.listenTo(Adapt, 'device:resize', this.onDeviceResize);
this.listenTo(Adapt, {
'contentObjectView:ready': this.changed,
'view:animationStart': this.changed,
'device:resize': this.onDeviceResize
});
this.listenTo(Adapt.parentView, 'preRemove', this.remove);
if (!this.isStatic) {
// Should not hide static tooltips on blur
$(document).on('mouseleave blur', '[data-tooltip-id]', this.onMouseOut);
}
this.unchangedRenders = 0;
this.changed();
}

Expand Down Expand Up @@ -152,7 +157,7 @@ export default class TooltipItemView extends Backbone.View {
}

doSubsequentPasses() {
if (!this.model) return;
if (!this.model) return false;
this.model.set('hasLoaded', true, { silent: true });
const multipassCache = {};
// First pass - render at the requested position
Expand All @@ -179,6 +184,10 @@ export default class TooltipItemView extends Backbone.View {
this.model.set('isShown', true, { silent: true });
this.render();
this.model.set('wasShown', true, { silent: true });
const endHash = JSON.stringify(this.model.get('tooltipStyles'));
const hasChanged = (this.startHash !== endHash);
this.startHash = endHash;
return hasChanged;
}

render() {
Expand All @@ -193,7 +202,15 @@ export default class TooltipItemView extends Backbone.View {
if (!this.model) return;
requestAnimationFrame(() => {
this.doFirstPass();
this.doSubsequentPasses();
const hasChanged = this.doSubsequentPasses();
// rerender if unchanged for 34 frames (1second @ 30fps)
if (!hasChanged) this.unchangedRenders++;
if (hasChanged) this.unchangedRenders = 0;
if (this.unchangedRenders >= 34) {
this.unchangedRenders = 0;
return;
}
this.changed();
});
}

Expand Down
2 changes: 2 additions & 0 deletions js/views/adaptView.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class AdaptView extends Backbone.View {
const minVerticalInview = onscreen._percentInviewVertical || 33;
if (m.percentInviewVertical < minVerticalInview) return;
this.$el.addClass(`${onscreen._classes}-after`).off('onscreen.adaptView');
const type = this.model.get('_type');
Adapt.trigger(`${type}View:animationStart view:animationStart`, this);
});
}

Expand Down
Loading