-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@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
1 parent
0c343d0
commit bfc6bc6
Showing
5 changed files
with
262 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters