Skip to content

Commit

Permalink
Addiction of function to get all numbers return to textfield
Browse files Browse the repository at this point in the history
  • Loading branch information
LordWeli committed May 6, 2021
1 parent 47d6ed6 commit f333702
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 8 deletions.
Binary file removed assets/adaptive-icon.png
Binary file not shown.
Binary file removed assets/favicon.png
Binary file not shown.
Binary file removed assets/icon.png
Binary file not shown.
Binary file added assets/images/addition_styled_button.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/create_layout.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/splash.png
Binary file not shown.
13 changes: 9 additions & 4 deletions src/components/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import { StyleSheet, View, TextInput } from 'react-native';
import ButtonsBody from './buttons/ButtonsBody'

export default function(props) {
const [numbers, setNumbers] = useState();
const [numbers, setNumbers] = useState([]);


const updateSetNumbers = (value) => {
setNumbers(value)
setNumbers([...numbers, value])
}

const clearInput = () => {
setNumbers([])
}

return (
<View style={styles(props).container}>
<View style={styles(props).areaContainer}>
<TextInput editable={false} style={styles(props).textArea} textAlign='right' value={numbers}/>
<ButtonsBody updateState={updateSetNumbers} theme={props.theme}/>
<TextInput editable={false} style={styles(props).textArea} textAlign='right' value={numbers.join(' ')}/>
<ButtonsBody updateState={updateSetNumbers} clearInput={clearInput} theme={props.theme}/>
</View>
</View>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/buttons/ButtonsBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function(props) {
{
titles.line.map((text, text_index) => {
return (
<CommandButton valueButton={text} key={text_index} updateNumber={props.updateState} theme={props.theme}/>
<CommandButton valueButton={text} key={text_index} updateNumber={props.updateState} clearInput={props.clearInput} theme={props.theme}/>
)
})
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/buttons/CommandButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ import React from 'react';
import { StyleSheet, TouchableOpacity, Text } from 'react-native';

export default function(props) {
const operators = ['C', '%', '*', '←', '/', '-', '+', '.', '=', '≠']
const operators = ['C', '%', '*', '←', '/', '-', '+', '=', '≠']

const getButtonText = (value) => {
if(checkIsOperator(value)) { getOperator(value) }
if(checkIsNumeric(value)) { getNumber(value) }
if(value == 'C') { props.clearInput() }
}

const checkIsOperator = (value) => {
return operators.includes(value)
}

const checkIsNumeric = (value) => {
return /^-?\d+$/.test(value)
return /^-?\d+$/.test(value) || value == '.'
}

const getNumber = (value) => {
props.updateNumber(value)
}

const getOperator = (value) => {
props.updateNumber(value)
// props.updateNumber(value)
}

return (
Expand Down

0 comments on commit f333702

Please sign in to comment.