Skip to content

Commit 4b36ffd

Browse files
committed
add cookbook for easier target creation, allow frameloop to be called manually
1 parent 5ff6e4f commit 4b36ffd

File tree

5 files changed

+80
-7
lines changed

5 files changed

+80
-7
lines changed

rollup.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ export default [
9191
...createConfig('targets/native', 'native'),
9292
...createConfig('targets/universal', 'universal'),
9393
...createConfig('targets/konva', 'konva'),
94+
{
95+
input: `./src/targets/cookbook/index`,
96+
output: { file: `dist/cookbook.js`, format: 'esm' },
97+
external,
98+
plugins: [
99+
babel(
100+
getBabelOptions(
101+
{ useESModules: true },
102+
'>1%, not dead, not ie 11, not op_mini all'
103+
)
104+
),
105+
resolve({ extensions }),
106+
],
107+
},
94108
...createCjs('renderprops/targets/web', 'renderprops'),
95109
...createCjs('renderprops/addons', 'renderprops-addons'),
96110
...createCjs('renderprops/targets/native', 'renderprops-native'),

src/animated/FrameLoop.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import Animated from './Animated'
22
import Controller from './Controller'
3-
import { now, requestFrame } from './Globals'
3+
import { now, requestFrame, manualFrameloop } from './Globals'
44

55
let active = false
66
const controllers = new Set()
77

8-
const frameLoop = () => {
8+
const update = () => {
9+
if (!active) return
910
let time = now()
1011
for (let controller of controllers) {
1112
let isActive = false
@@ -126,16 +127,17 @@ const frameLoop = () => {
126127
}
127128

128129
// Loop over as long as there are controllers ...
129-
if (controllers.size) requestFrame(frameLoop)
130-
else active = false
130+
if (controllers.size) {
131+
if (!manualFrameloop) requestFrame(update)
132+
} else active = false
131133
}
132134

133135
const start = (controller: Controller) => {
134136
if (!controllers.has(controller)) {
135137
controllers.add(controller)
136-
if (!active) requestFrame(frameLoop)
138+
if (!active && !manualFrameloop) requestFrame(update)
137139
active = true
138140
}
139141
}
140142

141-
export { start }
143+
export { start, update }

src/animated/Globals.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ export let createAnimatedStyle: (style: any) => AnimatedStyle
6666
export function injectCreateAnimatedStyle(factory: typeof createAnimatedStyle) {
6767
createAnimatedStyle = factory
6868
}
69+
70+
export let manualFrameloop = false
71+
export function injectManualFrameloop(manual: boolean) {
72+
manualFrameloop = manual
73+
}

src/targets/cookbook/index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import * as Globals from '../../animated/Globals'
2+
import AnimatedInterpolation, {
3+
interpolate,
4+
} from '../../animated/AnimatedInterpolation'
5+
import animated from '../../animated/createAnimatedComponent'
6+
import Interpolation from '../../animated/Interpolation'
7+
import Animated from '../../animated/Animated'
8+
import AnimatedArray from '../../animated/AnimatedArray'
9+
import AnimatedProps from '../../animated/AnimatedProps'
10+
import AnimatedStyle from '../../animated/AnimatedStyle'
11+
import AnimatedValue from '../../animated/AnimatedValue'
12+
import Controller from '../../animated/Controller'
13+
import * as frameloop from '../../animated/Frameloop'
14+
import * as colorMatchers from '../../shared/colorMatchers'
15+
import * as helpers from '../../shared/helpers'
16+
import * as constants from '../../shared/constants'
17+
import { config } from '../../shared/constants'
18+
import colorNames from '../../shared/colors'
19+
import normalizeColor from '../../shared/normalizeColors'
20+
import createInterpolation from '../../shared/interpolation'
21+
import { useChain } from '../../useChain'
22+
import { useSpring } from '../../useSpring'
23+
import { useSprings } from '../../useSprings'
24+
import { useTrail } from '../../useTrail'
25+
import { useTransition } from '../../useTransition'
26+
27+
export {
28+
Globals,
29+
AnimatedInterpolation,
30+
interpolate,
31+
animated,
32+
Interpolation,
33+
Animated,
34+
AnimatedArray,
35+
AnimatedProps,
36+
AnimatedStyle,
37+
AnimatedValue,
38+
Controller,
39+
frameloop,
40+
colorMatchers,
41+
helpers,
42+
constants,
43+
config,
44+
colorNames,
45+
normalizeColor,
46+
createInterpolation,
47+
useSpring,
48+
useTrail,
49+
useTransition,
50+
useChain,
51+
useSprings,
52+
}

src/targets/web/globals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ Globals.injectApplyAnimatedValues(
124124
} else return false
125125
},
126126
style => style
127-
)
127+
)

0 commit comments

Comments
 (0)