Skip to content

Animations #115

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 3 commits into from
Jun 23, 2025
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
1 change: 1 addition & 0 deletions src/addons/addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const addons = [
];

const newAddons = [
"animations",
"paint-gradient-maker",
"toolbox-full-blocks-on-hover",
"waveform-chunk-size",
Expand Down
43 changes: 43 additions & 0 deletions src/addons/addons/animations/_manifest_entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const manifest = {
"name": "Animation Types",
"description": "Change the intensity of animations that appear in the editor. Some moderate animations come with the editor by default.",
"credits": [
{
"name": "Reflow"
}
],
"userscripts": [
{
"url": "userscript.js"
}
],
"info": [
{
"text": "If you enabled a reduced motion setting on your device, these settings will not apply.",
"id": "reduced-motion"
}
],
"settings": [
{
"dynamic": true,
"name": "Intensity",
"id": "intensity",
"type": "select",
"potentialValues": [
{
"id": "default",
"name": "Moderate animations"
},
{
"id": "intense",
"name": "Shower me in animations"
}
],
"default": "default"
}
],
"tags": ["editor", "new"],
"enabledByDefault": true,
"dynamicDisable": true
};
export default manifest;
4 changes: 4 additions & 0 deletions src/addons/addons/animations/_runtime_entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import _js from "./userscript.js";
export const resources = {
"userscript.js": _js,
};
18 changes: 18 additions & 0 deletions src/addons/addons/animations/userscript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default async function ({ addon, console, msg }) {
function applySettings() {
ReduxStore.dispatch({
type: 'scratch-gui/addon-util/SET_EDITOR_ANIM_PREF',
animPref: addon.settings.get('intensity') || "none"
});
}
function resetSettings() {
ReduxStore.dispatch({
type: 'scratch-gui/addon-util/SET_EDITOR_ANIM_PREF',
animPref: "none"
});
}
addon.self.addEventListener("reenabled", applySettings);
addon.self.addEventListener("disabled", resetSettings);
addon.settings.addEventListener("change", applySettings);
applySettings();
}
1 change: 1 addition & 0 deletions src/addons/generated/addon-entries.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/addons/generated/addon-manifests.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ import _tw_straighten_comments from "../addons/tw-straighten-comments/_manifest_
import _tw_remove_feedback from "../addons/tw-remove-feedback/_manifest_entry.js";
import _tw_remove_backpack from "../addons/tw-remove-backpack/_manifest_entry.js";
import _tw_disable_cloud_variables from "../addons/tw-disable-cloud-variables/_manifest_entry.js";
import _animations from "../addons/animations/_manifest_entry.js";

export default {
"animations": _animations,
"cat-blocks": _cat_blocks,
"editor-devtools": _editor_devtools,
"find-bar": _find_bar,
Expand Down
16 changes: 16 additions & 0 deletions src/components/button/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
user-select: none;
}

.no-animation {
transition: transform 0s ease !important;
}

.button {
transition: transform 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95);
}

.button:hover {
transform: scale(1.02);
}

.button:active {
transform: scale(0.95);
}

.icon {
height: 1.5rem;
}
Expand Down
19 changes: 16 additions & 3 deletions src/components/button/button.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classNames from 'classnames';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import React from 'react';

Expand All @@ -13,16 +14,19 @@ const ButtonComponent = ({
iconHeight,
onClick,
children,
animPref,
...props
}) => {

const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (disabled) {
onClick = function () {};
}

const icon = iconSrc && (
<img
className={classNames(iconClassName, styles.icon)}
className={classNames(iconClassName, styles.icon, {
[styles.noAnimation]: animPref == 'none' || prefersReducedMotion
})}
draggable={false}
src={iconSrc}
height={iconHeight}
Expand All @@ -34,6 +38,7 @@ const ButtonComponent = ({
<span
className={classNames(
styles.outlinedButton,
styles.button,
className
)}
role="button"
Expand All @@ -57,4 +62,12 @@ ButtonComponent.propTypes = {
onClick: PropTypes.func
};

export default ButtonComponent;
const mapStateToProps = (state) => {
return {
animPref: state.scratchGui.addonUtil.editorAnimPref,
};
};

export default connect(
mapStateToProps
)(ButtonComponent);
14 changes: 14 additions & 0 deletions src/components/library-item/library-item.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@
border-radius: $space;
text-align: center;
cursor: pointer;
transition: transform 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95), border-color 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95);
}

.no-animation {
transition: transform 0s ease, border-color 0s ease !important;
}

.library-item:hover {
transform: scale(1.02);
}

.library-item:active {
transform: scale(0.98);
}

[theme="dark"] .library-item {
background: $ui-primary;
}
Expand Down
15 changes: 13 additions & 2 deletions src/components/library-item/library-item.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {FormattedMessage, intlShape, defineMessages} from 'react-intl';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import React from 'react';

import Box from '../box/box.jsx';
Expand Down Expand Up @@ -32,13 +33,15 @@ const getMSFormatted = (ms) => {
/* eslint-disable react/prefer-stateless-function */
class LibraryItemComponent extends React.PureComponent {
render() {
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
return this.props.featured ? (
<div
className={classNames(
styles.libraryItem,
styles.featuredItem,
{
[styles.disabled]: this.props.disabled
[styles.disabled]: this.props.disabled,
[styles.noAnimation]: this.props.animPref == 'none' || prefersReducedMotion,
},
typeof this.props.extensionId === 'string' ? styles.libraryItemExtension : null,
this.props.hidden ? styles.hidden : null
Expand Down Expand Up @@ -483,4 +486,12 @@ LibraryItemComponent.defaultProps = {
showPlayButton: false
};

export default LibraryItemComponent;
const mapStateToProps = (state) => {
return {
animPref: state.scratchGui.addonUtil.editorAnimPref,
};
};

export default connect(
mapStateToProps
)(LibraryItemComponent);
1 change: 1 addition & 0 deletions src/components/library/library.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class LibraryComponent extends React.Component {
contentLabel={this.props.title}
id={this.props.id}
onRequestClose={this.handleClose}
kind={this.props.kind}
>
{/*
todo: translation support?
Expand Down
14 changes: 14 additions & 0 deletions src/components/menu/menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@
overflow: visible;
color: $ui-white;
box-shadow: 0 8px 8px 0 $ui-black-transparent-default;
transform-origin: top left;
opacity: 0;
transform: scale(0.6);
transition: opacity 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95), transform 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95);
}

.no-animation {
transition: opacity 0s ease, transform 0s ease !important;
}

.menu-visible {
opacity: 1;
transform: scale(1);
}

[theme="dark"] .menu {
background-color: $motion-primary-dark;
}
Expand Down
67 changes: 46 additions & 21 deletions src/components/menu/menu.jsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
import classNames from 'classnames';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import React from 'react';

import React, {useState, useEffect, useRef} from 'react';
import styles from './menu.css';



const MenuComponent = ({
className = '',
children,
componentRef,
animPref,
place = 'right'
}) => (
<ul
className={classNames(
styles.menu,
className,
{
[styles.left]: place === 'left',
[styles.right]: place === 'right'
}
)}
ref={componentRef}
>
{children}
</ul>
);
}, props) => {
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const animIn = animPref == "none" ? 0 : 0; // ms, you could add a delay but it doesn't feel right
const [visible, setVisible] = useState(false); // provides a clear way to check visibility
const waitOut = useRef(null);

useEffect(() => {
const waitIn = setTimeout(() => setVisible(true), animIn);
return () => {
clearTimeout(waitIn);
if (waitOut.current) clearTimeout(waitOut.current);
};
}, []);
return (
<ul
className={classNames(
styles.menu,
className,
{
[styles.left]: place === 'left',
[styles.right]: place === 'right',
[styles.menuVisible]: visible,
[styles.noAnimation]: animPref == 'none' || prefersReducedMotion
}
)}
ref={componentRef}
>
{children}
</ul>
)
};

MenuComponent.propTypes = {
children: PropTypes.node,
Expand Down Expand Up @@ -77,8 +96,14 @@ MenuSection.propTypes = {
children: PropTypes.node
};

export {
MenuComponent as default,
MenuItem,
MenuSection
export { MenuItem, MenuSection };

const mapStateToProps = (state) => {
return {
animPref: state.scratchGui.addonUtil.editorAnimPref,
};
};

export default connect(
mapStateToProps
)(MenuComponent);
44 changes: 44 additions & 0 deletions src/components/modal/modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
bottom: 0;
z-index: $z-index-modal;
background-color: $ui-modal-overlay;
opacity: 0;
transition: opacity 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95);
}

.modal-overlay-visible {
opacity: 1;
}

.scrollable {
overflow: auto;
}
Expand All @@ -19,6 +26,43 @@
box-sizing: border-box;
}

.full-screen {
opacity: 0;
transform: scale(0);
transition: opacity 0.5s cubic-bezier(0.63, 0.32, 0.08, 0.95), transform 0.5s cubic-bezier(0.63, 0.32, 0.08, 0.95);
-webkit-perspective: 240px;
perspective: 240px;
}

.modal-container {
opacity: 0;
transform: scale(0.7) rotateX(-45deg);
transition: opacity 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95), transform 0.2s cubic-bezier(0.63, 0.32, 0.08, 0.95);
-webkit-perspective: 240px;
perspective: 240px;
max-width: max(60%, 750px);
width: max(60%, 750px);
}


.no-animation {
transition: opacity 0s ease, transform 0s ease !important;
}

.modal-fs-visible {
opacity: 1;
transform: scale(1) rotateX(0deg);
}

.modal-visible {
opacity: 1;
transform: scale(1) rotateX(0deg);
}

.ext-modal {
transform-origin: bottom left;
}

.modal-content {
margin: 100px auto;
outline: none;
Expand Down
Loading