Simple Counter

Screen is created using these React Native Core Components: <SafeAreaView />, <View />, <TouchableOpacity />, <Text />

import React from 'react';
import {
  StyleSheet,
  SafeAreaView,
  View,
  TouchableOpacity,
  Text,
} from 'react-native';

export default function Example() {
  const [value, setValue] = React.useState(0);

  return (
    <SafeAreaView style={{ flex: 1, backgroundColor: '#fff' }}>
      <View style={styles.container}>
        <View style={styles.counter}>
          <TouchableOpacity
            disabled={value <= 0}
            onPress={() => {
              setValue(Math.max(value - 1, 0));
            }}
            style={styles.counterAction}>
            <Text style={styles.counterActionText}>-</Text>
          </TouchableOpacity>

          <Text style={styles.counterValue}>{value}</Text>

          <TouchableOpacity
            onPress={() => {
              setValue(value + 1);
            }}
            style={styles.counterAction}>
            <Text style={styles.counterActionText}>+</Text>
          </TouchableOpacity>
        </View>
      </View>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    padding: 24,
    flexGrow: 1,
    flexShrink: 1,
    flexBasis: 0,
  },
  /** Counter */
  counter: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
  },
  counterAction: {
    width: 34,
    height: 34,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    borderColor: '#98d0ca',
    borderWidth: 2,
    borderRadius: 9999,
  },
  counterActionText: {
    fontSize: 20,
    lineHeight: 20,
    fontWeight: '600',
    color: '#98d0ca',
  },
  counterValue: {
    minWidth: 44,
    fontSize: 19,
    fontWeight: '600',
    color: '#1d1d1d',
    textAlign: 'center',
    paddingHorizontal: 8,
  },
});

Explore more components

Over 100 Ready to Use React Native Components for all your needs.

Never miss a beat

Stay in the loop with our latest updates and offers - no spam, just the good stuff!