Haraka

You define the behavior states of the component, and then animate between them.
Usage
import Behavior from '@exodus/haraka'
box = React.createRef()
<Behavior
ref={this.box}
state={[
{ opacity: 1 },
{ opacity: 0.5 },
{ rotate: '45deg' }
{ translateX: 10, translateY: 10 }
{ scale: 1.1 }
]}
/>
this.box.current.goTo(1)
this.box.current.goTo(2)
this.box.current.goTo(3)
this.box.current.goTo(4)
this.box.current.goTo([1, 2, 3, 4])
<Behavior currentState={0} />
<Behavior currentState={1} />
Install
yarn add @exodus/haraka
Definition
type DefaultConfig = {
type?: 'spring' | 'timing',
onComplete?: func,
delay?: number,
ref?: bool,
unmount? bool,
...AnimatedSpringOptions,
...AnimatedTimingOptions,
}
type State = {
opacity?: number,
rotate?: string,
scale?: number,
translateX?: number,
translateY?: number,
config?: DefaultConfig,
}
type StyleProp = {
prop: string,
default: string | number | null,
transform: bool,
}
type Behavior = {
freeze?: bool,
config?: DefaultConfig,
clearStyleProps?: bool,
disabled?: bool,
state?: State[],
nativeDriver?: AnimatedValue,
children?: any,
clamp?: bool,
keys?: number[],
currentState?: number,
initialState?: number,
skipProps?: string[],
skipStyleProps?: string[],
style?: object,
styleProps?: StyleProp[],
unmounted?: bool,
faded?: bool,
absolute?: bool,
centered?: bool,
fixed?: bool,
full?: bool,
landing?: bool,
}
const presets = {
faded: [{ opacity: 0 }, { opacity: 1 }],
}
const layoutPresets = {
absolute: { bottom: 0, left: 0, position: 'absolute', right: 0, top: 0 },
centered: { alignSelf: 'center' },
fixed: { position: 'absolute' },
full: { flex: 1 },
landing: { alignItems: 'center', flex: 1, justifyContent: 'center' },
}
behavior.goTo(index: number | number[], config?: DefaultConfig = {})
behavior.unmount()
behavior.mount(state: ?number)
behavior.key
behavior.setNativeProps({} : Props)
Examples
Available here.