Skip to content

Instantly share code, notes, and snippets.

// navbar can be imperatively set / overrode via context
// this is a little automagical, but also allows for unlimited flexibility including changing route title within one route (e.g. intentBuilder)
class SomeScene extends Component {
componentWillMount() {
this.context.navbar.set({
left,
middle,
right,
//...
@rt2zz
rt2zz / animator.js
Last active March 23, 2016 04:07
animations
import React, {
Animated,
Component,
PropTypes,
} from 'react-native'
import _ from 'lodash'
import config from '../config'
class Animation extends Component {
@rt2zz
rt2zz / notes.js
Last active March 19, 2016 05:29
import stringify from 'json-stringify-safe'
// use a special rehydrating reducer
const rehydratingReducer = (state, action) => {
if (action.type === 'REHYDRATE') return action.payload
else return reducer(state, action)
}
// subscribe to store and serialize safely
// should either debounce or selectively run this method as it is expensive
<DrawerIOS
disabled={!!this.props.modalValues.hasModals}
ref="drawer"
type="static"
content={sidebarContent}
onOpen={() => this.setState({isDrawerOpened: true})}
onClose={() => this.setState({isDrawerOpened: false})}
onOpenStart={() => {
this._hideKeyboard();
this._setStatusBarHidden(true);
try {
let data = await getSomeData()
processData(data)
// ... do more stuff
} catch (err) {
// handle bad data or exception
}
import React, {
Component,
View,
Text,
TouchableOpacity,
StyleSheet ,
} from 'react-native'
@rt2zz
rt2zz / AppNavigator.js
Created January 27, 2016 05:22
navigation-rfc + redux
@connect(state => ({navState: state.navState})
export default class AppNavigator {
render () {
return (
<NavigationAnimatedView
navigationState={this.props.navState}
style={styles.animatedView}
springConfig={{velocity: 1, tension: 50, friction: 11}}
renderOverlay={(props) => <View />}
renderScene={(route, index, navState, position, layout) => {
@rt2zz
rt2zz / lifecycle.js
Last active January 14, 2016 22:49
delay render
export default class App extends Component {
state = {initialized: false}
componentWillMount () {
persistStore(store, config, () => {
this.setState({initialized: true})
})
}
isSomethingTrue
? doA()
: isSomethingElseTrue
? doB()
: doC()
// ...
<Camera ref='camera' target='disk' />
// ...
this.refs.camera.takePicture((err, data) => {
NativeFileUploader(uploadUrl, {file: data.uri}, (err, data) => {
// ...
})
})