Skip to content

Instantly share code, notes, and snippets.

@breeko
Created July 4, 2018 12:19
Show Gist options
  • Select an option

  • Save breeko/c7caffc07cee27013fe2af53892b2612 to your computer and use it in GitHub Desktop.

Select an option

Save breeko/c7caffc07cee27013fe2af53892b2612 to your computer and use it in GitHub Desktop.
Calculator button layout for OpenCalc
//@flow
import React, {Component} from 'react';
import {View, StyleSheet} from 'react-native';
import CalculatorButton from './CalculatorButton';
type Props = {
handleButtonPress: (string) => any,
reset: () => any,
deleteLast: () => any,
switchButton: () => any,
}
export default class CalculatorButtonsContainer extends Component<Props> {
render() {
const {handleButtonPress, reset, deleteLast, switchButton} = this.props;
return (
<View style={styles.container}>
<View style={styles.row}>
<View style={styles.switchButtonGroup}>
<CalculatorButton operator={'<'} handleButtonPress={switchButton}/>
</View>
<View style={styles.buttonGroup}>
<View style={styles.row}>
<CalculatorButton operator={'c'} handleButtonPress={reset}/>
<CalculatorButton operator={'('} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={')'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'←'} handleButtonPress={deleteLast}/>
</View>
<View style={styles.row}>
<CalculatorButton operator={'7'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'8'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'9'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'÷'} handleButtonPress={handleButtonPress}/>
</View>
<View style={styles.row}>
<CalculatorButton operator={'4'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'5'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'6'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'×'} handleButtonPress={handleButtonPress}/>
</View>
<View style={styles.row}>
<CalculatorButton operator={'1'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'2'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'3'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'−'} handleButtonPress={handleButtonPress}/>
</View>
<View style={styles.row}>
<CalculatorButton operator={'.'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'0'} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'='} handleButtonPress={handleButtonPress}/>
<CalculatorButton operator={'+'} handleButtonPress={handleButtonPress}/>
</View>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 3,
},
row: {
flex: 1,
flexDirection: 'row',
},
buttonGroup: {
flex: 10,
},
switchButtonGroup: {
flex: 1,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment