diff --git a/src/components/buttons/ButtonsBody.js b/src/components/buttons/ButtonsBody.js index 1d8b9aa..d1aae50 100644 --- a/src/components/buttons/ButtonsBody.js +++ b/src/components/buttons/ButtonsBody.js @@ -3,38 +3,46 @@ import { View, StyleSheet } from 'react-native'; import CommandButton from './CommandButton'; export default function() { + const button_text = [ + { + line: ['C', '%', '*', '←'], + method: 'getButtonText()' + }, + { + line: ['7', '8', '9', '/'], + method: 'getButtonText()' + }, + { + line: ['4', '5', '6', '-'], + method: 'getButtonText()' + }, + { + line: ['1', '2', '3', '+'], + method: 'getButtonText()' + }, + { + line: ['≠', '0', '.', '='], + method: 'getButtonText()' + } + ] + return ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + { + button_text.map((titles) => { + return ( + + { + titles.line.map((text) => { + return ( + + ) + }) + } + + ) + }) + } ); } diff --git a/src/components/buttons/CommandButton.js b/src/components/buttons/CommandButton.js index 85daa28..55527d6 100644 --- a/src/components/buttons/CommandButton.js +++ b/src/components/buttons/CommandButton.js @@ -2,9 +2,32 @@ import React from 'react'; import { StyleSheet, TouchableOpacity, Text } from 'react-native'; export default function(props) { + const operators = ['C', '%', '*', '←', '/', '-', '+', '.', '=', '≠'] + + const getButtonText = (value) => { + if(checkIsOperator(value)) { getOperator(value) } + if(checkIsNumeric(value)) { getNumber(value) } + } + + const checkIsOperator = (value) => { + return operators.includes(value) + } + + const checkIsNumeric = (value) => { + return /^-?\d+$/.test(value) + } + + const getNumber = (value) => { + console.log('Number') + } + + const getOperator = (value) => { + console.log('Operator') + } + return ( - - {props.valueNumber} + + {props.valueButton} ) }