Skip to content

Commit 2cafc18

Browse files
authored
Merge pull request #115 from mmmmaaaaarrrrrrkkkkkkkk/develop
Animations
2 parents 2654ca8 + 9c6430f commit 2cafc18

File tree

20 files changed

+511
-189
lines changed

20 files changed

+511
-189
lines changed

src/addons/addons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const addons = [
7777
];
7878

7979
const newAddons = [
80+
"animations",
8081
"paint-gradient-maker",
8182
"toolbox-full-blocks-on-hover",
8283
"waveform-chunk-size",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const manifest = {
2+
"name": "Animation Types",
3+
"description": "Change the intensity of animations that appear in the editor. Some moderate animations come with the editor by default.",
4+
"credits": [
5+
{
6+
"name": "Reflow"
7+
}
8+
],
9+
"userscripts": [
10+
{
11+
"url": "userscript.js"
12+
}
13+
],
14+
"info": [
15+
{
16+
"text": "If you enabled a reduced motion setting on your device, these settings will not apply.",
17+
"id": "reduced-motion"
18+
}
19+
],
20+
"settings": [
21+
{
22+
"dynamic": true,
23+
"name": "Intensity",
24+
"id": "intensity",
25+
"type": "select",
26+
"potentialValues": [
27+
{
28+
"id": "default",
29+
"name": "Moderate animations"
30+
},
31+
{
32+
"id": "intense",
33+
"name": "Shower me in animations"
34+
}
35+
],
36+
"default": "default"
37+
}
38+
],
39+
"tags": ["editor", "new"],
40+
"enabledByDefault": true,
41+
"dynamicDisable": true
42+
};
43+
export default manifest;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import _js from "./userscript.js";
2+
export const resources = {
3+
"userscript.js": _js,
4+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default async function ({ addon, console, msg }) {
2+
function applySettings() {
3+
ReduxStore.dispatch({
4+
type: 'scratch-gui/addon-util/SET_EDITOR_ANIM_PREF',
5+
animPref: addon.settings.get('intensity') || "none"
6+
});
7+
}
8+
function resetSettings() {
9+
ReduxStore.dispatch({
10+
type: 'scratch-gui/addon-util/SET_EDITOR_ANIM_PREF',
11+
animPref: "none"
12+
});
13+
}
14+
addon.self.addEventListener("reenabled", applySettings);
15+
addon.self.addEventListener("disabled", resetSettings);
16+
addon.settings.addEventListener("change", applySettings);
17+
applySettings();
18+
}

src/addons/generated/addon-entries.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/addons/generated/addon-manifests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ import _tw_straighten_comments from "../addons/tw-straighten-comments/_manifest_
7171
import _tw_remove_feedback from "../addons/tw-remove-feedback/_manifest_entry.js";
7272
import _tw_remove_backpack from "../addons/tw-remove-backpack/_manifest_entry.js";
7373
import _tw_disable_cloud_variables from "../addons/tw-disable-cloud-variables/_manifest_entry.js";
74+
import _animations from "../addons/animations/_manifest_entry.js";
7475

7576
export default {
77+
"animations": _animations,
7678
"cat-blocks": _cat_blocks,
7779
"editor-devtools": _editor_devtools,
7880
"find-bar": _find_bar,

src/components/button/button.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
user-select: none;
1313
}
1414

15+
.no-animation {
16+
transition: transform 0s ease !important;
17+
}
18+
19+
.button {
20+
transition: transform 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95);
21+
}
22+
23+
.button:hover {
24+
transform: scale(1.02);
25+
}
26+
27+
.button:active {
28+
transform: scale(0.95);
29+
}
30+
1531
.icon {
1632
height: 1.5rem;
1733
}

src/components/button/button.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import classNames from 'classnames';
2+
import { connect } from 'react-redux';
23
import PropTypes from 'prop-types';
34
import React from 'react';
45

@@ -13,16 +14,19 @@ const ButtonComponent = ({
1314
iconHeight,
1415
onClick,
1516
children,
17+
animPref,
1618
...props
1719
}) => {
18-
20+
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
1921
if (disabled) {
2022
onClick = function () {};
2123
}
2224

2325
const icon = iconSrc && (
2426
<img
25-
className={classNames(iconClassName, styles.icon)}
27+
className={classNames(iconClassName, styles.icon, {
28+
[styles.noAnimation]: animPref == 'none' || prefersReducedMotion
29+
})}
2630
draggable={false}
2731
src={iconSrc}
2832
height={iconHeight}
@@ -34,6 +38,7 @@ const ButtonComponent = ({
3438
<span
3539
className={classNames(
3640
styles.outlinedButton,
41+
styles.button,
3742
className
3843
)}
3944
role="button"
@@ -57,4 +62,12 @@ ButtonComponent.propTypes = {
5762
onClick: PropTypes.func
5863
};
5964

60-
export default ButtonComponent;
65+
const mapStateToProps = (state) => {
66+
return {
67+
animPref: state.scratchGui.addonUtil.editorAnimPref,
68+
};
69+
};
70+
71+
export default connect(
72+
mapStateToProps
73+
)(ButtonComponent);

src/components/library-item/library-item.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,21 @@
2121
border-radius: $space;
2222
text-align: center;
2323
cursor: pointer;
24+
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);
2425
}
26+
27+
.no-animation {
28+
transition: transform 0s ease, border-color 0s ease !important;
29+
}
30+
31+
.library-item:hover {
32+
transform: scale(1.02);
33+
}
34+
35+
.library-item:active {
36+
transform: scale(0.98);
37+
}
38+
2539
[theme="dark"] .library-item {
2640
background: $ui-primary;
2741
}

src/components/library-item/library-item.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {FormattedMessage, intlShape, defineMessages} from 'react-intl';
22
import PropTypes from 'prop-types';
3+
import { connect } from 'react-redux';
34
import React from 'react';
45

56
import Box from '../box/box.jsx';
@@ -32,13 +33,15 @@ const getMSFormatted = (ms) => {
3233
/* eslint-disable react/prefer-stateless-function */
3334
class LibraryItemComponent extends React.PureComponent {
3435
render() {
36+
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
3537
return this.props.featured ? (
3638
<div
3739
className={classNames(
3840
styles.libraryItem,
3941
styles.featuredItem,
4042
{
41-
[styles.disabled]: this.props.disabled
43+
[styles.disabled]: this.props.disabled,
44+
[styles.noAnimation]: this.props.animPref == 'none' || prefersReducedMotion,
4245
},
4346
typeof this.props.extensionId === 'string' ? styles.libraryItemExtension : null,
4447
this.props.hidden ? styles.hidden : null
@@ -483,4 +486,12 @@ LibraryItemComponent.defaultProps = {
483486
showPlayButton: false
484487
};
485488

486-
export default LibraryItemComponent;
489+
const mapStateToProps = (state) => {
490+
return {
491+
animPref: state.scratchGui.addonUtil.editorAnimPref,
492+
};
493+
};
494+
495+
export default connect(
496+
mapStateToProps
497+
)(LibraryItemComponent);

src/components/library/library.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ class LibraryComponent extends React.Component {
306306
contentLabel={this.props.title}
307307
id={this.props.id}
308308
onRequestClose={this.handleClose}
309+
kind={this.props.kind}
309310
>
310311
{/*
311312
todo: translation support?

src/components/menu/menu.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@
1313
overflow: visible;
1414
color: $ui-white;
1515
box-shadow: 0 8px 8px 0 $ui-black-transparent-default;
16+
transform-origin: top left;
17+
opacity: 0;
18+
transform: scale(0.6);
19+
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);
1620
}
21+
22+
.no-animation {
23+
transition: opacity 0s ease, transform 0s ease !important;
24+
}
25+
26+
.menu-visible {
27+
opacity: 1;
28+
transform: scale(1);
29+
}
30+
1731
[theme="dark"] .menu {
1832
background-color: $motion-primary-dark;
1933
}

src/components/menu/menu.jsx

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
11
import classNames from 'classnames';
2+
import { connect } from 'react-redux';
23
import PropTypes from 'prop-types';
3-
import React from 'react';
4-
4+
import React, {useState, useEffect, useRef} from 'react';
55
import styles from './menu.css';
66

7+
8+
79
const MenuComponent = ({
810
className = '',
911
children,
1012
componentRef,
13+
animPref,
1114
place = 'right'
12-
}) => (
13-
<ul
14-
className={classNames(
15-
styles.menu,
16-
className,
17-
{
18-
[styles.left]: place === 'left',
19-
[styles.right]: place === 'right'
20-
}
21-
)}
22-
ref={componentRef}
23-
>
24-
{children}
25-
</ul>
26-
);
15+
}, props) => {
16+
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
17+
const animIn = animPref == "none" ? 0 : 0; // ms, you could add a delay but it doesn't feel right
18+
const [visible, setVisible] = useState(false); // provides a clear way to check visibility
19+
const waitOut = useRef(null);
20+
21+
useEffect(() => {
22+
const waitIn = setTimeout(() => setVisible(true), animIn);
23+
return () => {
24+
clearTimeout(waitIn);
25+
if (waitOut.current) clearTimeout(waitOut.current);
26+
};
27+
}, []);
28+
return (
29+
<ul
30+
className={classNames(
31+
styles.menu,
32+
className,
33+
{
34+
[styles.left]: place === 'left',
35+
[styles.right]: place === 'right',
36+
[styles.menuVisible]: visible,
37+
[styles.noAnimation]: animPref == 'none' || prefersReducedMotion
38+
}
39+
)}
40+
ref={componentRef}
41+
>
42+
{children}
43+
</ul>
44+
)
45+
};
2746

2847
MenuComponent.propTypes = {
2948
children: PropTypes.node,
@@ -77,8 +96,14 @@ MenuSection.propTypes = {
7796
children: PropTypes.node
7897
};
7998

80-
export {
81-
MenuComponent as default,
82-
MenuItem,
83-
MenuSection
99+
export { MenuItem, MenuSection };
100+
101+
const mapStateToProps = (state) => {
102+
return {
103+
animPref: state.scratchGui.addonUtil.editorAnimPref,
104+
};
84105
};
106+
107+
export default connect(
108+
mapStateToProps
109+
)(MenuComponent);

src/components/modal/modal.css

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
bottom: 0;
1111
z-index: $z-index-modal;
1212
background-color: $ui-modal-overlay;
13+
opacity: 0;
14+
transition: opacity 0.15s cubic-bezier(0.63, 0.32, 0.08, 0.95);
1315
}
16+
17+
.modal-overlay-visible {
18+
opacity: 1;
19+
}
20+
1421
.scrollable {
1522
overflow: auto;
1623
}
@@ -19,6 +26,43 @@
1926
box-sizing: border-box;
2027
}
2128

29+
.full-screen {
30+
opacity: 0;
31+
transform: scale(0);
32+
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);
33+
-webkit-perspective: 240px;
34+
perspective: 240px;
35+
}
36+
37+
.modal-container {
38+
opacity: 0;
39+
transform: scale(0.7) rotateX(-45deg);
40+
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);
41+
-webkit-perspective: 240px;
42+
perspective: 240px;
43+
max-width: max(60%, 750px);
44+
width: max(60%, 750px);
45+
}
46+
47+
48+
.no-animation {
49+
transition: opacity 0s ease, transform 0s ease !important;
50+
}
51+
52+
.modal-fs-visible {
53+
opacity: 1;
54+
transform: scale(1) rotateX(0deg);
55+
}
56+
57+
.modal-visible {
58+
opacity: 1;
59+
transform: scale(1) rotateX(0deg);
60+
}
61+
62+
.ext-modal {
63+
transform-origin: bottom left;
64+
}
65+
2266
.modal-content {
2367
margin: 100px auto;
2468
outline: none;

0 commit comments

Comments
 (0)