forked from syrjs/core
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Derek Anderson
committed
Jan 31, 2018
1 parent
34098da
commit 7e8f789
Showing
9 changed files
with
232 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ class styler { | |
element.style[key] = value; | ||
} | ||
} | ||
element.style.overflow = 'hidden'; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { | ||
Component, | ||
Render, | ||
View, | ||
Dimensions, | ||
Animated, | ||
Text, | ||
Button, | ||
Image, | ||
TouchableOpacity, | ||
LinearGradient, | ||
PixelRatio, | ||
Platform, | ||
NativeModules | ||
} from '../index'; | ||
|
||
import { Styles } from './styles'; | ||
|
||
const operations = { | ||
'+' : (oldValue, newValue) => { | ||
return oldValue*1 + newValue*1; | ||
}, | ||
'-' : (oldValue, newValue) => { | ||
return oldValue*1 - newValue*1; | ||
}, | ||
'x' : (oldValue, newValue) => { | ||
return oldValue * newValue; | ||
}, | ||
'/' : (oldValue, newValue) => { | ||
return oldValue / newValue; | ||
} | ||
}; | ||
|
||
class SyrCalculator extends Component { | ||
constructor() { | ||
super(); | ||
this.state.displayAreaValue = '0'; | ||
this.state.calculations = []; | ||
} | ||
render() { | ||
return ( | ||
<View style={Styles.mainView}> | ||
<Text style={Styles.displayArea}>{this.state.displayAreaValue}</Text> | ||
<View style={Styles.buttons}> | ||
<Button onPress={()=>{this.onPressHandler(1)}} style={Styles.numButton(1)}>1</Button> | ||
<Button onPress={()=>{this.onPressHandler(2)}} style={Styles.numButton(2)}>2</Button> | ||
<Button onPress={()=>{this.onPressHandler(3)}} style={Styles.numButton(3)}>3</Button> | ||
<Button onPress={()=>{this.onPressHandler(4)}} style={Styles.numButton(4)}>4</Button> | ||
<Button onPress={()=>{this.onPressHandler(5)}} style={Styles.numButton(5)}>5</Button> | ||
<Button onPress={()=>{this.onPressHandler(6)}} style={Styles.numButton(6)}>6</Button> | ||
<Button onPress={()=>{this.onPressHandler(7)}} style={Styles.numButton(7)}>7</Button> | ||
<Button onPress={()=>{this.onPressHandler(8)}} style={Styles.numButton(8)}>8</Button> | ||
<Button onPress={()=>{this.onPressHandler(9)}} style={Styles.numButton(9)}>9</Button> | ||
</View> | ||
<Button onPress={()=>{this.onPressHandler('+')}} style={Styles.plus}>+</Button> | ||
</View> | ||
); | ||
} | ||
calculate() { | ||
let runningValue = 0; | ||
this.state.calculations.forEach( (element, index) => { | ||
if(isNaN(element*1)) { | ||
let prev = this.state.calculations[index-1]; | ||
let next = this.state.calculations[index+1]; | ||
|
||
if(prev && next) { | ||
prev = index > 0 ? runningValue : prev; | ||
runningValue = operations[element](prev, next); | ||
} | ||
} | ||
}); | ||
return runningValue; | ||
} | ||
onPressHandler(btn) { | ||
let displayAreaValue; | ||
|
||
if(this.state.clearNextEntry) { | ||
this.state.clearNextEntry = false; | ||
this.state.displayAreaValue = ''; | ||
} | ||
|
||
if(operations[btn]) { | ||
if(this.state.displayAreaValue.length > 0) { | ||
this.state.calculations.push(this.state.displayAreaValue); | ||
} | ||
this.state.calculations.push(btn); | ||
this.state.clearNextEntry = true; | ||
displayAreaValue = this.state.displayAreaValue; | ||
this.calculate(); | ||
} else { | ||
displayAreaValue = this.state.displayAreaValue == '0' ? '' : this.state.displayAreaValue; | ||
displayAreaValue = displayAreaValue + '' + btn | ||
} | ||
|
||
this.setState({ | ||
displayAreaValue: displayAreaValue | ||
}) | ||
} | ||
} | ||
|
||
Render(SyrCalculator); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { | ||
Dimensions, | ||
PixelRatio | ||
} from '../../index'; | ||
PixelRatio.setBaseScreenSize(PixelRatio.baseDisplays.iPhoneSE); | ||
|
||
const Styles = { | ||
mainView: { | ||
width: Dimensions.get('window').width, | ||
height: Dimensions.get('window').height, | ||
backgroundColor: '#aaaaaa' | ||
}, | ||
buttons: { | ||
width: PixelRatio.getPixelSizeForLayoutSize(600), | ||
height: PixelRatio.getPixelSizeForLayoutSize(600), | ||
top: PixelRatio.getPixelSizeForLayoutSize(200) | ||
}, | ||
numButton: function (number) { | ||
const row = Math.floor(number / 3) - (number % 3 ? 0 : 1); | ||
const col = number % 3 ? number % 3 : 3; // 0, 1, 2 | ||
const width = Dimensions.get('window').width / 5; | ||
const height = Dimensions.get('window').height / 7; | ||
const padding = PixelRatio.getPixelSizeForLayoutSize(10); | ||
|
||
const left = ((col - 1) * width) + (padding * col); | ||
const top = (row * height) + (padding * row); | ||
|
||
return { | ||
height: height, | ||
width: width, | ||
backgroundColor: '#eeeeee', | ||
left: left, | ||
top: top | ||
} | ||
}, | ||
displayArea: { | ||
textAlign: 'right', | ||
height: PixelRatio.getPixelSizeForLayoutSize(125), | ||
top: PixelRatio.getPixelSizeForLayoutSize(50), | ||
left: PixelRatio.getPixelSizeForLayoutSize(10), | ||
width: Dimensions.get('window').width - PixelRatio.getPixelSizeForLayoutSize(20), | ||
backgroundColor: '#dedede', | ||
fontSize: PixelRatio.getPixelSizeForLayoutSize(105) | ||
}, | ||
plus: { | ||
width: PixelRatio.getPixelSizeForLayoutSize(200), | ||
height: PixelRatio.getPixelSizeForLayoutSize(200), | ||
backgroundColor: "#f49b42", | ||
fontSize: PixelRatio.getPixelSizeForLayoutSize(60), | ||
left:Dimensions.get('window').width - PixelRatio.getPixelSizeForLayoutSize(200) -PixelRatio.getPixelSizeForLayoutSize(10), | ||
top: PixelRatio.getPixelSizeForLayoutSize(200) | ||
} | ||
} | ||
|
||
export { | ||
Styles | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters