Skip to content

Instantly share code, notes, and snippets.

@alexkuttig
alexkuttig / Stars.jsx
Last active January 30, 2018 09:28
React Native setState with callback
const URL = 'https://api.github.com/repos/facebook/react-native'
class Stars extends Component {
state : {
stars: number
} = {
stars: 0
}
async componentDidMount() {
const URL = 'https://api.github.com/repos/facebook/react-native'
class Stars extends Component {
state : {
stars: number
} = {
stars: 0
}
async componentDidMount() {
@alexkuttig
alexkuttig / DimensionsHelper.js
Created March 24, 2018 13:47
DimensionsHelper for react-native
// @flow
'use strict';
import {
Platform,
StatusBar,
Dimensions
} from 'react-native';
import { isIphoneX } from 'react-native-iphone-x-helper';
export const statusBarHeight = Platform.OS === 'ios' ? (isIphoneX() ? 44 : 20) : StatusBar.currentHeight;
import {
statusBarHeight,
headerHeight,
SafeAreaWithHeader,
} from './DimensionsHelper';
const vw: number = SafeAreaWithHeader.vw;
const vh: number = SafeAreaWithHeader.vh;
class ViewWithTitle extends Component {
renderTitle = () => {
if (this.props.title) {
if (Platform.OS === 'ios') {
return (
<View style={[styles.iOSTitleContainer, {height: this.headerHeight}]}>
<Text style={styles.iOSTitle}>
{this.props.title}
</Text>
</View>
)
state: {
scrollY: Animated.Value,
} = {
scrollY: new Animated.Value(0)
};
renderContentArea = () => {
if (this.props.children) {
return (
<ScrollView
if (Platform.OS === 'ios') {
let titleOpacity = this.state.scrollY.interpolate({
inputRange: [0, 41, 48],
outputRange: [0, 0, 1],
extrapolate: 'clamp'
});
let borderBottomColor = this.state.scrollY.interpolate({
inputRange: [56, 57],
outputRange: ["#ffffff", '#f2f2f2'],
extrapolate: 'clamp'
renderIOSBigTitle = () => {
if (Platform.OS === 'ios' && this.props.title) {
const fontSize = this.state.scrollY.interpolate({
inputRange: [-50, 0],
outputRange: [40, 34],
extrapolate: 'clamp'
});
const top = this.state.scrollY.interpolate({
inputRange: [0, 70],
outputRange: [0, -70]
// @flow
'use strict';
import React, {Component} from 'react';
import {
StyleSheet,
Text,
View,
Platform,
FlatList,
Animated,
const Tab = createBottomTabNavigator();
export default function App() {
return (
<NavigationNativeContainer>
<Tab.Navigator>
<Tab.Screen name="Home" screen={HomeScreen} />
<Tab.Screen name="Settings" screen={SettingsScreen} />
</Tab.Navigator>
</NavigationNativeContainer>