Skip to content

Commit

Permalink
Highlight changed lines
Browse files Browse the repository at this point in the history
  • Loading branch information
pomber committed Mar 17, 2019
1 parent 3def52b commit 2543dfb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/airframe/airframe.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import easing from "./easing";
const MULTIPLY = "multiply";

/* eslint-disable */
function mergeResults(results) {
function mergeResults(results, composite) {
const firstResult = results[0];
if (results.length < 2) {
return firstResult;
}
if (Array.isArray(firstResult)) {
// console.log("merge", results);
return firstResult.map((_, i) => {
return mergeResults(results.map(result => result[i]));
return mergeResults(results.map(result => result[i]), composite);
});
} else {
return Object.assign({}, ...results);
const merged = Object.assign({}, ...results);

if (composite === MULTIPLY) {
const opacities = results.map(x => x.opacity).filter(x => x != null);
if (opacities.length !== 0) {
merged.opacity = opacities.reduce((a, b) => a * b);
}
}
return merged;
}
}

const airframe = {
parallel: ({ children: fns }) => {
return (t, ...args) => {
const styles = fns.map(fn => fn(t, ...args));
const result = mergeResults(styles);
const result = mergeResults(styles, MULTIPLY);
return result;
};
},
Expand Down
18 changes: 17 additions & 1 deletion src/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ function GrowHeight() {
);
}

function SwitchLines({ filterExit, filterEnter }) {
const offOpacity = 0.4;
function SwitchLines({ filterExit, filterEnter, filterFadeOut }) {
return (
<parallel>
<Stagger interval={0.2} filter={filterExit}>
Expand All @@ -59,6 +60,19 @@ function SwitchLines({ filterExit, filterEnter }) {
<SlideFromRight />
</chain>
</Stagger>
<Stagger interval={0} filter={filterEnter}>
<tween from={{ opacity: offOpacity }} to={{ opacity: 1 }} />
</Stagger>
<Stagger interval={0} filter={filterFadeOut}>
<tween
from={{ opacity: 1 }}
to={{ opacity: offOpacity }}
ease={easing.easeOutCubic}
/>
</Stagger>
<Stagger interval={0} filter={l => !filterEnter(l) && !filterFadeOut(l)}>
<tween from={{ opacity: offOpacity }} to={{ opacity: offOpacity }} />
</Stagger>
</parallel>
);
}
Expand All @@ -68,10 +82,12 @@ export default (
<SwitchLines
filterExit={line => line.left && !line.middle}
filterEnter={line => !line.left && line.middle}
filterFadeOut={line => false}
/>
<SwitchLines
filterExit={line => line.middle && !line.right}
filterEnter={line => !line.middle && line.right}
filterFadeOut={line => !line.left && line.middle}
/>
</chain>
);

0 comments on commit 2543dfb

Please sign in to comment.