Skip to content

Instantly share code, notes, and snippets.

View nirsky's full-sized avatar

Nir Hadassi nirsky

View GitHub Profile
import React from 'react';
import { View, Text, Dimensions, StyleSheet, TouchableOpacity } from 'react-native';
import { loremIpsum } from './contants';
const { width, height } = Dimensions.get('window');
const AwesomeComponent = () =>
<View style={styles.container}>
<View style={styles.box}>
<Text style={styles.title}>Awesome Blog Post Page</Text>
<Text style={styles.text}>{loremIpsum}</Text>
import React from 'react';
import { View, Text, Dimensions, StyleSheet, TouchableOpacity } from 'react-native';
import { loremIpsum } from './contants';
const { width, height } = Dimensions.get('window');
const AwesomeComponent = () =>
<View style={styles.container}>
<View style={styles.box}>
<Text style={styles.title}>Awesome Blog Post Page</Text>
<Text style={styles.text}>{loremIpsum}</Text>
import React from 'react';
import { View, Text, Dimensions, StyleSheet, TouchableOpacity } from 'react-native';
import { loremIpsum } from './contants';
const { width, height } = Dimensions.get('window');
const AwesomeComponent = () =>
<View style={styles.container}>
<View style={styles.box}>
<Text style={styles.title}>Awesome Blog Post Page</Text>
<Text style={styles.text}>{loremIpsum}</Text>
const styles = StyleSheet.create({
container: {
width: width,
height: height,
backgroundColor: '#E0E0E0',
alignItems: 'center',
justifyContent: 'center',
},
box: {
width: 300,
const FlexExample = () =>
<View style={[styles.container, {flex: 1}]}>
<View style={{flex: 16}}/>
<View style={{flexDirection: 'row', flex: 68}}>
<View style={{flex: 1}}/>
<View style={[styles.box, {flex: 8}]}>
<Text style={styles.title}>Awesome Blog Post Page</Text>
<Text style={styles.text}>{loremIpsum}</Text>
<View style={styles.buttonsContainer}>
<TouchableOpacity style={styles.button}>
import {vw, vh} from 'react-native-viewport-units';
const styles = StyleSheet.create({
container: {
...
},
box: {
width: 80 * vw,
height: 67 * vh,
padding: 2.6 * vw,
import { Dimensions } from 'react-native';
const { width, height } = Dimensions.get('window');
//Guideline sizes are based on standard ~5" screen mobile device
const guidelineBaseWidth = 350;
const guidelineBaseHeight = 680;
const scale = size => width / guidelineBaseWidth * size;
const verticalScale = size => height / guidelineBaseHeight * size;
const moderateScale = (size, factor = 0.5) => size + ( scale(size) - size ) * factor;
//Class
class CounterButton extends Component {
constructor() {
super();
this.state = {
count: 0
}
}
render() {
return <button onClick={() => this.setState({ count: this.state.count + 1 })}>
const Timer = (props) => {
const intervalRef = useRef();
useEffect(() => {
const id = setInterval(() => {
// ...
});
intervalRef.current = id;
return () => {
clearInterval(intervalRef.current);
const Counter = props => {
const [count, setCount] = useState(0);
const prevCountRef = useRef();
useEffect(() => {
prevCountRef.current = count;
});
const prevCount = prevCountRef.current;
return <h1>Now: {count}, before: {prevCount}</h1>;