Skip to content

Commit

Permalink
[fixed] JSSDemo
Browse files Browse the repository at this point in the history
@kof's original JSSDemo PR didn't work on not-his machine.  It depended on a version of `symbol-observable` that conflicted with the one we depend on.  Now that I've identified and fixed that issue (with a `resolutions` field in `package.json`), it can be brought back.

When cssinjs/jss#613 is fixed, the demo can be simplified further, because `foreground$` and `background$` can be directly assigned to their selectors.
  • Loading branch information
appsforartists committed Nov 1, 2017
1 parent 0c343d0 commit bfc6bc6
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"packages/*"
],
"resolutions": {
"symbol-observable": "1.0.4",
"uws": "8.14.1"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/demos-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"deploy": "yarn run build; ../../node_modules/.bin/firebase deploy"
},
"dependencies": {
"jss": "9.1",
"jss-preset-default": "4.0.1",
"jsxstyle": "1.0.2",
"material-motion": "0.0.0",
"material-motion-views-dom": "0.0.0",
Expand Down
158 changes: 158 additions & 0 deletions packages/demos-react/src/JSSDemo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/** @license
* Copyright 2016 - present The Material Motion Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

import * as React from 'react';

import jss from 'jss';
import preset from 'jss-preset-default';

import {
MaybeReactive,
NumericDict,
ObservableWithMotionOperators,
combineLatest,
subscribe,
} from 'material-motion';

import {
combineStyleStreams,
getPointerEventStreamsFromElement,
viewportDimensions$,
} from 'material-motion-views-dom';

import {
AttachStreams,
TransformTarget,
} from 'material-motion-views-react';

jss.setup(preset());

const createStyleSheet = ({ foreground$, background$ }) => {
// There's a bug in JSS 9.1 that only lets one selector have an observable
// value, so for now, we manually pluck the style values.
const sheet = jss.createStyleSheet(
{
container: {
touchAction: 'none',
width: '100vw',
height: '100vh',
overflow: 'hidden',
background: '#F7DF1E',
},

foreground: {
transform: foreground$.pluck('transform'),
},

background: {
transform: background$.pluck('transform'),
},
},
{
link: true,
}
).attach();

return sheet.classes;
})

const getLayerTranslateStreams = () => {
const {
move$,
} = getPointerEventStreamsFromElement(document);

const centeredMove$ = move$.subtractedBy(
combineLatest<NumericDict, MaybeReactive<NumericDict>>({
x: viewportDimensions$.pluck('width').dividedBy(2),
y: viewportDimensions$.pluck('height').dividedBy(2),
})
);

return {
background$: combineStyleStreams({
translate$: centeredMove$.multipliedBy({ x: 1.125, y: 0.25 }),
}),

foreground$: combineStyleStreams({
translate$: centeredMove$.multipliedBy({ x: .75, y: 0.11 }),
}),
};
}

export class JSSDemo extends React.Component<{}, {}> {
classes = createStyleSheet(getLayerTranslateStreams());

render() {
return (
<div className = { this.classes.container }>
<RandomLogos
className = { this.classes.foreground }
scale = { 3 }
/>

<RandomLogos
className = { this.classes.background }
scale = { 5 }
/>
</div>
);
}
}
export default JSSDemo;

// Since JSS uses `<style>` elements, it doesn't force its children to rerender
// on each frame. That allows this otherwise-expensive component to be
// functional, since it will never be re-rendered.
function RandomLogos({ scale, ...propsPassthrough }) {
return (
<div
style = {
{
position: 'relative',
}
}
{ ...propsPassthrough }
>
{
new Array(100).fill().map(
(_, i) => (
<div
key = { i }
style = {
{
position: 'absolute',
color: '#222222',
fontWeight: 'bold',
transform: `
translate(
${ Math.round(Math.random() * 500 - 200) / 2 }vw,
${ Math.round(Math.random() * 200) / 2 }vh
)
scale(${ scale })
`,
userSelect: 'none',
}
}
>
JSS
</div>
)
)
}
</div>
);
}
6 changes: 6 additions & 0 deletions packages/demos-react/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Router from 'react-router/BrowserRouter';

// import ExampleMain from './example/components/ExampleMain';
import ArticulableFinger from './ArticulableFinger';
import JSSDemo from './JSSDemo';
import ParallaxDemo from './ParallaxDemo';
import QuickiePointerEventTest from './QuickiePointerEventTest';
import SwipeableDemo from './SwipeableDemo';
Expand Down Expand Up @@ -56,6 +57,11 @@ const links = [
name: 'ParallaxDemo',
component: ParallaxDemo,
},
{
href: '/parallax-jss/',
name: 'JSSDemo',
component: JSSDemo,
},
{
href: '/pointer-events/',
name: 'QuickiePointerEventTest',
Expand Down
100 changes: 95 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,12 @@ crypto-random-string@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"

css-vendor@^0.3.8:
version "0.3.8"
resolved "https://registry.yarnpkg.com/css-vendor/-/css-vendor-0.3.8.tgz#6421cfd3034ce664fe7673972fd0119fc28941fa"
dependencies:
is-in-browser "^1.0.2"

csv-streamify@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/csv-streamify/-/csv-streamify-3.0.4.tgz#4cb614c57e3f299cca17b63fdcb4ad167777f47a"
Expand Down Expand Up @@ -2729,6 +2735,10 @@ is-glob@^2.0.0, is-glob@^2.0.1:
dependencies:
is-extglob "^1.0.0"

is-in-browser@^1.0.2, is-in-browser@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/is-in-browser/-/is-in-browser-1.1.3.tgz#56ff4db683a078c6082eb95dad7dc62e1d04f835"

is-npm@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-npm/-/is-npm-1.0.0.tgz#f2fb63a65e4905b406c86072765a1a4dc793b9f4"
Expand All @@ -2753,6 +2763,12 @@ is-obj@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-obj/-/is-obj-1.0.1.tgz#3e4729ac1f5fde025cd7d83a896dab9f4f67db0f"

is-observable@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/is-observable/-/is-observable-0.2.0.tgz#b361311d83c6e5d726cabf5e250b0237106f5ae2"
dependencies:
symbol-observable "^0.2.2"

is-plain-obj@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
Expand Down Expand Up @@ -2950,6 +2966,84 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.3.6"

jss-camel-case@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/jss-camel-case/-/jss-camel-case-6.0.0.tgz#7cf8453e395c31fed931d11efbc885edcd61132e"

jss-compose@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/jss-compose/-/jss-compose-5.0.0.tgz#ce01b2e4521d65c37ea42cf49116e5f7ab596484"
dependencies:
warning "^3.0.0"

jss-default-unit@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/jss-default-unit/-/jss-default-unit-8.0.0.tgz#a308ead4f587ebe17cc845f9870867400de90910"
dependencies:
is-observable "^0.2.0"

jss-expand@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/jss-expand/-/jss-expand-5.0.0.tgz#8eadb782f29ec5f1d285451dd38052d5ac51644a"
dependencies:
is-observable "^0.2.0"

jss-extend@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/jss-extend/-/jss-extend-6.0.1.tgz#e53430bc92a42e50d036883ccfecfbc4e1199147"
dependencies:
is-observable "^0.2.0"
warning "^3.0.0"

jss-global@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/jss-global/-/jss-global-3.0.0.tgz#e19e5c91ab2b96353c227e30aa2cbd938cdaafa2"

jss-nested@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/jss-nested/-/jss-nested-6.0.1.tgz#ef992b79d6e8f63d939c4397b9d99b5cbbe824ca"
dependencies:
warning "^3.0.0"

jss-preset-default@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/jss-preset-default/-/jss-preset-default-4.0.1.tgz#822cecb87c27ff91633774422f4c221d61486b65"
dependencies:
jss-camel-case "^6.0.0"
jss-compose "^5.0.0"
jss-default-unit "^8.0.0"
jss-expand "^5.0.0"
jss-extend "^6.0.1"
jss-global "^3.0.0"
jss-nested "^6.0.1"
jss-props-sort "^6.0.0"
jss-template "^1.0.0"
jss-vendor-prefixer "^7.0.0"

jss-props-sort@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/jss-props-sort/-/jss-props-sort-6.0.0.tgz#9105101a3b5071fab61e2d85ea74cc22e9b16323"

jss-template@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/jss-template/-/jss-template-1.0.0.tgz#4b874608706ddceecacdb5567e254aecb6ea69b3"
dependencies:
warning "^3.0.0"

jss-vendor-prefixer@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/jss-vendor-prefixer/-/jss-vendor-prefixer-7.0.0.tgz#0166729650015ef19d9f02437c73667231605c71"
dependencies:
css-vendor "^0.3.8"

jss@9.1:
version "9.1.0"
resolved "https://registry.yarnpkg.com/jss/-/jss-9.1.0.tgz#601f18478a26ac95a128f919d2e481088e93b28f"
dependencies:
is-in-browser "^1.1.3"
is-observable "^0.2.0"
warning "^3.0.0"

jsxstyle@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/jsxstyle/-/jsxstyle-1.0.2.tgz#10ccc3a229a89f6b04c581200ba7c699f76a3344"
Expand Down Expand Up @@ -5327,14 +5421,10 @@ supports-color@^4.0.0:
dependencies:
has-flag "^2.0.0"

symbol-observable@1.0.4:
symbol-observable@1.0.4, symbol-observable@^0.2.2, symbol-observable@^0.2.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.4.tgz#29bf615d4aa7121bdd898b22d4b3f9bc4e2aa03d"

symbol-observable@^0.2.4:
version "0.2.4"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-0.2.4.tgz#95a83db26186d6af7e7a18dbd9760a2f86d08f40"

tapable@^0.2.5, tapable@~0.2.5:
version "0.2.6"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.6.tgz#206be8e188860b514425375e6f1ae89bfb01fd8d"
Expand Down

0 comments on commit bfc6bc6

Please sign in to comment.