Browse Source

implement scroll picker

pull/8/head
Tim Glasgow 2 years ago
parent
commit
9bae90809f
  1. 58
      squarenotsquare/src/components/ScrollingPicker.js
  2. 22
      squarenotsquare/src/screens/Home.js
  3. 5
      squarenotsquare/src/screens/styles/AppStyles.js
  4. 3
      squarenotsquare/src/themes/Icons.js

58
squarenotsquare/src/components/ScrollingPicker.js

@ -0,0 +1,58 @@
import React, { useRef, useState } from "react";
import {
ScrollView,
Animated,
} from "react-native";
import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons';
import Icons from '../themes/Icons';
import Colors from "../themes/Colors";
import Metrics from "../themes/Metrics";
import { styles } from "../screens/styles/AppStyles";
function ScrollingPicker() {
const scrollX = useRef(new Animated.Value(0)).current;
const [selected, setSelected] = useState(0);
function onScroll(event){
if (event.nativeEvent.contentOffset.x === 0) {
setSelected(0);
} else if (event.nativeEvent.contentOffset.x === Metrics.icons.buttonIcon) {
setSelected(1);
}
Animated.event([
{
nativeEvent: {
contentOffset: {
x: scrollX
}
}
}
], {useNativeDriver: true})
}
return (
<ScrollView
horizontal={true}
pagingEnabled={true}
showsHorizontalScrollIndicator={false}
style={styles.modePicker}
onScroll={onScroll}
scrollEventThrottle={0}
>
<MaterialIcon
key={0}
name={Icons.squareIcons.square}
color={Colors.material.green400}
size={Metrics.icons.buttonIcon}
/>
<MaterialIcon
key={1}
name={Icons.squareIcons.plus}
color={Colors.material.green400}
size={Metrics.icons.buttonIcon}
/>
</ScrollView>
);
}
export default ScrollingPicker;

22
squarenotsquare/src/screens/Home.js

@ -9,6 +9,7 @@ import Slider from "../components/Slider";
import { useDispatch } from "react-redux"; import { useDispatch } from "react-redux";
import {squareStartPressed} from '../redux/actions/UserActions'; import {squareStartPressed} from '../redux/actions/UserActions';
import { goToScores } from "../redux/actions/SystemActions"; import { goToScores } from "../redux/actions/SystemActions";
import ModePicker from '../components/ScrollingPicker';
function Home(){ function Home(){
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -36,16 +37,21 @@ function Home(){
size={Metrics.icons.buttonIcon} size={Metrics.icons.buttonIcon}
/> />
</TouchableOpacity> </TouchableOpacity>
<View style={[styles.flexHalf, styles.spaceAround]}> <View style={[styles.flexHalf, styles.spaceEvenly]}>
<Text style={[styles.boldText, styles.headerTitleFont, styles.centeredText, styles.darkText]}> <View style={styles.flex}>
Square <Text style={[styles.boldText, styles.headerTitleFont, styles.centeredText, styles.darkText]}>
<Text style={[styles.green, styles.headerTitleFont, styles.centeredText, styles.lightText]}>
{' not '}
</Text>
<Text style={[styles.headerTitleFont, styles.centeredText, styles.darkText]}>
Square Square
<Text style={[styles.green, styles.headerTitleFont, styles.centeredText, styles.lightText]}>
{' not '}
</Text>
<Text style={[styles.headerTitleFont, styles.centeredText, styles.darkText]}>
Square
</Text>
</Text> </Text>
</Text> </View>
<View style={[styles.flex, styles.centeredSelf]}>
<ModePicker />
</View>
</View> </View>
<View style={[styles.flex, styles.centeredItems, styles.spaceEvenly]}> <View style={[styles.flex, styles.centeredItems, styles.spaceEvenly]}>
<Slider origin={400} duration={750} delay={0}> <Slider origin={400} duration={750} delay={0}>

5
squarenotsquare/src/screens/styles/AppStyles.js

@ -111,6 +111,11 @@ export const styles = StyleSheet.create({
height: Metrics.icons.buttonIcon height: Metrics.icons.buttonIcon
}, },
modePicker: {
width: Metrics.icons.buttonIcon,
overflow: "visible"
},
timerView: { timerView: {
height: Metrics.screenSections.timerHeight height: Metrics.screenSections.timerHeight
} }

3
squarenotsquare/src/themes/Icons.js

@ -4,7 +4,8 @@ class AppIcons {
settings: 'cog-outline', settings: 'cog-outline',
toggleOn: 'toggle-switch-on', toggleOn: 'toggle-switch-on',
toggleOff: 'toggle-switch-off', toggleOff: 'toggle-switch-off',
check: 'check' check: 'check',
plus: 'plus'
}; };
wrongShapes = { wrongShapes = {

Loading…
Cancel
Save