Skip to content

Commit

Permalink
createStyleMap => getStyleMap
Browse files Browse the repository at this point in the history
  • Loading branch information
lintonye committed Mar 12, 2017
1 parent 80cc59d commit 96c2920
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import faker from 'faker';
const {createTransition, initTransition, together, sq, Transitions} = Transition;

const Slide = createTransition({
createStyleMap(
getStyleMap(
itemsOnFromRoute: Array<*>,
itemsOnToRoute: Array<*>,
transitionOptions,
Expand Down Expand Up @@ -44,7 +44,7 @@ const SlideScene = initTransition(Slide, /\$scene.+/);

const StaggeredAppear = (filter) => ({
filter,
createStyleMap(
getStyleMap(
itemsOnFromRoute: Array<*>,
itemsOnToRoute: Array<*>,
transitionProps) {
Expand Down Expand Up @@ -84,7 +84,7 @@ const StaggeredAppear = (filter) => ({

const NoOp = (filter) => ({
filter,
createStyleMap() {
getStyleMap() {
console.log('NoOp transition called');
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/views/CardStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ class CardStack extends Component<DefaultProps, Props, void> {
return result;
}, {});

const styleMap = transition.createStyleMap &&
this._interpolateStyleMap(transition.createStyleMap(fromItems, toItems, transitionProps), transitionProps);
const styleMap = transition.getStyleMap &&
this._interpolateStyleMap(transition.getStyleMap(fromItems, toItems, transitionProps), transitionProps);
let inPlaceStyleMap = {
from: {
...styleMap && styleMap.from,
Expand All @@ -420,8 +420,8 @@ class CardStack extends Component<DefaultProps, Props, void> {
const itemsToClone = transition.getItemsToClone && transition.getItemsToClone(fromItems, toItems);
if (!itemsToClone) return null;

let styleMap = transition.createStyleMapForClones &&
this._interpolateStyleMap(transition.createStyleMapForClones(fromItems, toItems, transitionProps), transitionProps);
let styleMap = transition.getStyleMapForClones &&
this._interpolateStyleMap(transition.getStyleMapForClones(fromItems, toItems, transitionProps), transitionProps);
styleMap = styleMap && this._replaceFromToInStyleMap(styleMap, fromRouteName, toRouteName);

// TODO what if an item is the parent of another item?
Expand Down
2 changes: 1 addition & 1 deletion src/views/Transition/Transitions/CrossFade.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { createTransition } from '../transitionHelpers';

const CrossFade = createTransition({
createStyleMap(
getStyleMap(
itemsOnFromRoute: Array<*>,
itemsOnToRoute: Array<*>,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/Transition/Transitions/Scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { createTransition } from '../transitionHelpers';

const Scale = createTransition({
createStyleMap(
getStyleMap(
itemsOnFromRoute: Array<*>,
itemsOnToRoute: Array<*>,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/Transition/Transitions/SharedElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const SharedElement = createTransition({
const onBoth = item => itemIdsOnBoth.includes(item.id);
return itemsOnFromRoute.filter(onBoth).concat(itemsOnToRoute.filter(onBoth));
},
createStyleMapForClones(
getStyleMapForClones(
itemsOnFromRoute: Array<*>,
itemsOnToRoute: Array<*>,
transitionProps) {
Expand Down
20 changes: 10 additions & 10 deletions src/views/Transition/composition.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const mergeStyleMap = (left, right) => ({
const toFixed = (n: number) => Math.round(n * 1e12) / 1e12;

export function sequence(...transitions) {
const createStyleMapOp = (op: string) => (
const getStyleMapOp = (op: string) => (
itemsOnFromRoute: Array<*>,
itemsOnToRoute: Array<*>,
transitionProps) => {
Expand All @@ -86,18 +86,18 @@ export function sequence(...transitions) {
return finalResult.styleMap;
};
const duration = transitions.reduce((sum, t) => sum + t.duration, 0);
const createStyleMap = createStyleMapOp('createStyleMap');
const createStyleMapForClones = createStyleMapOp('createStyleMapForClones');
const getStyleMap = getStyleMapOp('getStyleMap');
const getStyleMapForClones = getStyleMapOp('getStyleMapForClones');
return {
...combineCommonProps(transitions),
duration,
createStyleMap,
createStyleMapForClones,
getStyleMap,
getStyleMapForClones,
};
}

export function together(...transitions) {
const createStyleMapOp = (op: string) => (
const getStyleMapOp = (op: string) => (
itemsOnFromRoute: Array<*>,
itemsOnToRoute: Array<*>,
transitionProps) => transitions.reduce((result, t) => {
Expand All @@ -109,13 +109,13 @@ export function together(...transitions) {
return result;
}, {});
const duration = transitions.reduce((max, t) => Math.max(max, t.duration), 0);
const createStyleMap = createStyleMapOp('createStyleMap');
const createStyleMapForClones = createStyleMapOp('createStyleMapForClones');
const getStyleMap = getStyleMapOp('getStyleMap');
const getStyleMapForClones = getStyleMapOp('getStyleMapForClones');
return {
...combineCommonProps(transitions),
duration,
createStyleMap,
createStyleMapForClones,
getStyleMap,
getStyleMapForClones,
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/views/Transition/transitionHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ const mashStyleMap = (styleMap, duration: number) => {
}

export function createTransition(transitionConfig) {
const { createStyleMap, createStyleMapForClones, canUseNativeDriver, ...rest } = transitionConfig;
const createStyleMapHO = (op, duration) => (...args) => {
const { getStyleMap, getStyleMapForClones, canUseNativeDriver, ...rest } = transitionConfig;
const getStyleMapHO = (op, duration) => (...args) => {
const originalStyleMap = transitionConfig[op] && transitionConfig[op](...args);
return mashStyleMap(originalStyleMap, duration);
};
return (filter) => (duration: number) => ({
filter,
duration,
canUseNativeDriver: canUseNativeDriver || (() => true),
createStyleMap: createStyleMapHO('createStyleMap', duration),
createStyleMapForClones: createStyleMapHO('createStyleMapForClones', duration),
getStyleMap: getStyleMapHO('getStyleMap', duration),
getStyleMapForClones: getStyleMapHO('getStyleMapForClones', duration),
...rest,
});
}
2 changes: 1 addition & 1 deletion src/views/TransitionConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function defaultTransitionConfig(

const defaultTransition = (filter) => ({
filter,
createStyleMap(
getStyleMap(
itemsOnFromRoute: Array<*>,
itemsOnToRoute: Array<*>,
transitionProps) {
Expand Down
12 changes: 6 additions & 6 deletions src/views/__tests__/transitionComposition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('together', () => {
const A = initTestTransition('a', null, [a1, a2]);
const B = initTestTransition('b', null, [b1, b2]);
const combined = together(A(0.1), B(0.5));
const styleMap = combined.createStyleMap([], []);
const styleMap = combined.getStyleMap([], []);
const { from: {id1: {a, b}}} = styleMap;
assertIoRanges(a, {inputRange: [0, 0.1], outputRange: [a1, a2]});
assertIoRanges(b, {inputRange: [0, 0.5], outputRange: [b1, b2]});
Expand All @@ -33,7 +33,7 @@ describe('sequence', () => {
const A = initTestTransition('a', null, [a1, a2]);
const B = initTestTransition('b', null, [b1, b2]);
const combined = sequence(A(0.1), B(0.2));
const styleMap = combined.createStyleMap([], []);
const styleMap = combined.getStyleMap([], []);
const { from: {id1: {a, b}}} = styleMap;
assertIoRanges(a, {inputRange: [0, 0.1], outputRange: [a1, a2]});
assertIoRanges(b, {inputRange: [0.1, 0.3], outputRange: [b1, b2]});
Expand All @@ -44,7 +44,7 @@ describe('sequence', () => {
const B = initTestTransition('b', null, [b1, b2]);
const C = initTestTransition('c', null, [c1, c2]);
const combined = sequence(A(0.1), B(0.2), C(0.3));
const styleMap = combined.createStyleMap([], []);
const styleMap = combined.getStyleMap([], []);
const { from: {id1: {a, b, c}}} = styleMap;
assertIoRanges(a, {inputRange: [0, 0.1], outputRange: [a1, a2]});
assertIoRanges(b, {inputRange: [0.1, 0.3], outputRange: [b1, b2]});
Expand All @@ -56,7 +56,7 @@ describe('sequence', () => {
const B = initTestTransition('b', null, [b1, b2]);
const C = initTestTransition('c', null, [c1, c2]);
const combined = sequence(A(0.1), sequence(B(0.2), C(0.3)));
const styleMap = combined.createStyleMap([], []);
const styleMap = combined.getStyleMap([], []);
const { from: {id1: {a, b, c}}} = styleMap;
assertIoRanges(a, {inputRange: [0, 0.1], outputRange: [a1, a2]});
assertIoRanges(b, {inputRange: [0.1, 0.3], outputRange: [b1, b2]});
Expand All @@ -77,7 +77,7 @@ describe('Mixing together and sequence', () => {
const B = initTestTransition('b', null, [b1, b2]);
const C = initTestTransition('c', null, [c1, c2]);
const combined = sequence(A(0.1), together(B(0.2), C(0.4)));
const styleMap = combined.createStyleMap([], []);
const styleMap = combined.getStyleMap([], []);
const { from: {id1: {a, b, c}}} = styleMap;
assertIoRanges(a, {inputRange: [0, 0.1], outputRange: [a1, a2]});
assertIoRanges(b, {inputRange: [0.1, 0.3], outputRange: [b1, b2]});
Expand All @@ -89,7 +89,7 @@ describe('Mixing together and sequence', () => {
const B = initTestTransition('b', null, [b1, b2]);
const C = initTestTransition('c', null, [c1, c2]);
const combined = sequence(together(A(0.1), B(0.2)), C(0.4));
const styleMap = combined.createStyleMap([], []);
const styleMap = combined.getStyleMap([], []);
const { from: {id1: {a, b, c}}} = styleMap;
assertIoRanges(a, {inputRange: [0, 0.1], outputRange: [a1, a2]});
assertIoRanges(b, {inputRange: [0, 0.2], outputRange: [b1, b2]});
Expand Down
2 changes: 1 addition & 1 deletion src/views/__tests__/transitionHelpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { initTestTransition, assertIoRanges, ioRanges } from './transitionTestUt
describe('createTransition', () => {
it('returns styleMap based on duration: A(0.1)', () => {
const A = initTestTransition('a', [0, 1], [100, 200]);
const styleMap = A(0.1).createStyleMap();
const styleMap = A(0.1).getStyleMap();
const { from: { id1: { a } } } = styleMap;
assertIoRanges(a, ioRanges([0, 0.1], [100, 200]));
});
Expand Down
2 changes: 1 addition & 1 deletion src/views/__tests__/transitionTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createTransition, initTransition } from '../Transition/transitionHelper

export function initTestTransition(prop, inputRange, outputRange, filterRegex = /foo/) {
const transition = createTransition({
createStyleMap() {
getStyleMap() {
return {
from: {
id1: { [prop]: {inputRange, outputRange,} },
Expand Down

0 comments on commit 96c2920

Please sign in to comment.