Browse Source

Merge branch 'feature/button_colors' into develop

master
Dslak 6 years ago
parent
commit
278cafbeb3
  1. 21
      vds-app/App/components/Button.js
  2. 6
      vds-app/App/components/Variables.js
  3. 2
      vds-app/App/screens/Banner.js
  4. 9
      vds-app/App/screens/Exam.js
  5. 16
      vds-app/App/screens/Quiz.js
  6. 2
      vds-app/App/screens/Splash.js

21
vds-app/App/components/Button.js

@ -5,6 +5,8 @@ import { colors } from "../components/Variables"
const styles = StyleSheet.create({ const styles = StyleSheet.create({
button: { button: {
backgroundColor: colors.white_alpha, backgroundColor: colors.white_alpha,
borderWidth: 4,
borderColor: 'transparent',
borderRadius: 10, borderRadius: 10,
paddingHorizontal: 10, paddingHorizontal: 10,
paddingVertical: 10, paddingVertical: 10,
@ -31,20 +33,33 @@ const styles = StyleSheet.create({
} }
}) })
export const Button = ({ text, subtitle = null, isBig = false, onPress = () => {} }) => {
export const Button = ({ text, subtitle = null, isBig = false, colorize = false, onPress = () => {} }) => {
const buttonBig = isBig ? {fontSize: 25} : {} const buttonBig = isBig ? {fontSize: 25} : {}
const isClicked = colorize.clicked == colorize.id
let buttonColor = {backgroundColor: colors.white_alpha}
if(colorize && colorize.answered) {
if(colorize.isCorrect) {
buttonColor = {backgroundColor: colors.green_light, borderColor: isClicked ? colors.white_alpha : 'transparent'}
} else {
if(isClicked) {
buttonColor = {backgroundColor: colors.red_light, borderColor: isClicked ? colors.white_alpha : 'transparent'}
}
}
}
if(subtitle) { if(subtitle) {
return ( return (
<TouchableOpacity onPress={onPress} style={styles.button}>
<TouchableOpacity onPress={onPress} style={[styles.button, buttonColor]}>
<Text style={[styles.text, buttonBig]}>{text}</Text> <Text style={[styles.text, buttonBig]}>{text}</Text>
<Text style={styles.subtitle}>{subtitle}</Text> <Text style={styles.subtitle}>{subtitle}</Text>
</TouchableOpacity> </TouchableOpacity>
) )
} else { } else {
return ( return (
<TouchableOpacity onPress={onPress} style={styles.button}>
<TouchableOpacity onPress={onPress} style={[styles.button, buttonColor]}>
<Text style={[styles.text, buttonBig]}>{text}</Text> <Text style={[styles.text, buttonBig]}>{text}</Text>
</TouchableOpacity> </TouchableOpacity>
) )

6
vds-app/App/components/Variables.js

@ -4,19 +4,21 @@ export const colors = {
black: "#000", black: "#000",
purple: "#8c0072", purple: "#8c0072",
purple_light: "#a30085", purple_light: "#a30085",
blue: "#15a7f0",
blue: "#1385d0",
dark_blue: "#1279be", dark_blue: "#1279be",
red: "#af321e", red: "#af321e",
red_alpha: "rgba(175, 50, 30, 0.9)", red_alpha: "rgba(175, 50, 30, 0.9)",
red_light: "#af5d44",
green: "#28A125", green: "#28A125",
green_alpha: "rgba(40, 160, 40, 0.9)", green_alpha: "rgba(40, 160, 40, 0.9)",
green_light: "#6cc155",
yellow: "#e1ff3c", yellow: "#e1ff3c",
yellow_alpha: "rgba(225, 255, 60, 0.9)", yellow_alpha: "rgba(225, 255, 60, 0.9)",
orange: "#ff9b32" orange: "#ff9b32"
} }
export const texts = { export const texts = {
quizzes: "Seleziona un quiz",
quizzes: "Seleziona un argomento",
section_quizzes: "Quiz per argomento", section_quizzes: "Quiz per argomento",
exam: "Simulazione esame", exam: "Simulazione esame",
exam_simulation: "30 domande in 30min", exam_simulation: "30 domande in 30min",

2
vds-app/App/screens/Banner.js

@ -38,7 +38,7 @@ class Banner extends React.Component {
} }
bannerError = (e) => { bannerError = (e) => {
console.log("Banner error: ", e)
//console.log("Banner error: ", e)
} }
render() { render() {

9
vds-app/App/screens/Exam.js

@ -54,10 +54,10 @@ class Exam extends React.Component {
timer: maxTime timer: maxTime
} }
answer = correct => {
answer = (correct, id) => {
this.setState( this.setState(
state => { state => {
const nextState = { answered: true }
const nextState = { answered: true, clickedId: id }
if (correct) { if (correct) {
nextState.correctCount = state.correctCount + 1 nextState.correctCount = state.correctCount + 1
@ -71,7 +71,7 @@ class Exam extends React.Component {
}, },
() => { () => {
if(this.state.timer > 1 || (this.state.correctCount+this.state.wrongCount) < this.state.totalCount) { if(this.state.timer > 1 || (this.state.correctCount+this.state.wrongCount) < this.state.totalCount) {
setTimeout(() => this.nextQuestion(), 750)
setTimeout(() => this.nextQuestion(), correct ? 750 : 2000)
} }
} }
) )
@ -138,7 +138,8 @@ class Exam extends React.Component {
<Button <Button
key={answer.id} key={answer.id}
text={answer.text} text={answer.text}
onPress={() => this.answer(answer.correct)}
colorize={{id: answer.id, clicked: this.state.clickedId, answered: this.state.answered, isCorrect: answer.correct}}
onPress={() => this.answer(answer.correct, answer.id)}
/> />
))} ))}
</ButtonContainer> </ButtonContainer>

16
vds-app/App/screens/Quiz.js

@ -42,10 +42,10 @@ class Quiz extends React.Component {
results: false results: false
} }
answer = correct => {
answer = (correct, id) => {
this.setState( this.setState(
state => { state => {
const nextState = { answered: true }
const nextState = { answered: true, clickedId: id }
if (correct) { if (correct) {
nextState.correctCount = state.correctCount + 1 nextState.correctCount = state.correctCount + 1
@ -58,7 +58,7 @@ class Quiz extends React.Component {
return nextState return nextState
}, },
() => { () => {
setTimeout(() => this.nextQuestion(), 750)
setTimeout(() => this.nextQuestion(), correct ? 750 : 3000)
} }
) )
} }
@ -102,11 +102,12 @@ class Quiz extends React.Component {
<Text style={styles.text}>{question.question}</Text> <Text style={styles.text}>{question.question}</Text>
<ButtonContainer> <ButtonContainer>
{question.answers.map(answer => (
{question.answers.map( (answer, index) => (
<Button <Button
key={answer.id} key={answer.id}
text={answer.text} text={answer.text}
onPress={() => this.answer(answer.correct)}
colorize={{id: answer.id, clicked: this.state.clickedId, answered: this.state.answered, isCorrect: answer.correct}}
onPress={() => this.answer(answer.correct, answer.id)}
/> />
))} ))}
</ButtonContainer> </ButtonContainer>
@ -116,10 +117,7 @@ class Quiz extends React.Component {
{`${this.state.correctCount+this.state.wrongCount}/${this.state.totalCount}`} {`${this.state.correctCount+this.state.wrongCount}/${this.state.totalCount}`}
</Text> </Text>
</SafeAreaView> </SafeAreaView>
<Alert
correct={this.state.answerCorrect}
visible={this.state.answered}
/>
<Results <Results
total={this.state.totalCount} total={this.state.totalCount}
correct={this.state.correctCount} correct={this.state.correctCount}

2
vds-app/App/screens/Splash.js

@ -88,7 +88,7 @@ class Splash extends React.Component {
} }
bannerError = (e) => { bannerError = (e) => {
console.log("Banner error: ", e)
//console.log("Banner error: ", e)
} }
render() { render() {

Loading…
Cancel
Save