diff --git a/src/components/Buttons/MenuButton.tsx b/src/components/Buttons/MenuButton.tsx index 299c9bad..5a71d9b2 100644 --- a/src/components/Buttons/MenuButton.tsx +++ b/src/components/Buttons/MenuButton.tsx @@ -14,7 +14,7 @@ interface Props { const MenuButton: React.FunctionComponent = ({ navigation }) => { return ( { - navigation.navigate('List'); + navigation.goBack(); await analytics().logEvent('menu'); }}> ; + containerHeight: number; +} + +const GameBottomSheet: React.FunctionComponent = ({ navigation, containerHeight }) => { + const currentGameId = useAppSelector(state => state.settings.currentGameId); + if (typeof currentGameId == 'undefined') return null; + + const fullscreen = useAppSelector(state => state.settings.home_fullscreen); + const currentGame = useAppSelector(state => selectGameById(state, state.settings.currentGameId)); + + if (currentGame == undefined) return null; + + // ref + const bottomSheetRef = useRef(null); + + // variables + const snapPoints = useMemo(() => [bottomSheetHeight, '60%', '100%'], []); + + // State variable for the current snap point index + const [snapPointIndex, setSnapPointIndex] = useState(1); + + // Function to cycle through the snap points + const cycleSnapPoints = () => { + setSnapPointIndex((prevIndex) => { + const nextIndex = prevIndex + 1; + return nextIndex < snapPoints.length ? nextIndex : 0; + }); + }; + + // Function to snap to the next point when the button is pressed + const handleButtonPress = () => { + cycleSnapPoints(); + bottomSheetRef.current?.snapToIndex(snapPointIndex); + }; + + const animatedPosition = useSharedValue(0); + + const newStyles = useAnimatedStyle(() => { + const snapPoint0: number = typeof snapPoints[0] === 'string' + ? parseFloat(snapPoints[0]) / 100 * containerHeight + : containerHeight - snapPoints[0]; + + const delta = snapPoint0 - animatedPosition.value; + + const i = interpolate(delta, [0, 30], [0, 1], Extrapolate.CLAMP); + + return { + opacity: i + }; + }); + + return ( + + + + + + handleButtonPress()}> + {currentGame.title} + + navigation.navigate('Settings')}> + Edit + + + + + + + Tap on a column to set the current round. + + + + navigation.navigate('Share')}> + + + Share + + + + + + + + ); +}; + +const styles = StyleSheet.create({ + sheetHeaderContainer: { + flexDirection: 'row', + justifyContent: 'space-between', + paddingHorizontal: 10, + }, + sheetHeader: { + color: 'white', + fontSize: 20, + paddingTop: 0, + fontWeight: 'bold' + }, + sheetHeaderButton: { + paddingHorizontal: 10, + fontSize: 20, + color: systemBlue, + }, + sheetContent: { + padding: 10, + }, +}); + +export default GameBottomSheet; diff --git a/src/components/Headers/GameHeader.tsx b/src/components/Headers/GameHeader.tsx index 87f56240..1176055e 100644 --- a/src/components/Headers/GameHeader.tsx +++ b/src/components/Headers/GameHeader.tsx @@ -6,6 +6,7 @@ import analytics from '@react-native-firebase/analytics'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { ParamListBase } from '@react-navigation/native'; +import FullscreenButton from '../Buttons/FullscreenButton'; import { roundNext, roundPrevious } from '../../../redux/GamesSlice'; import { selectGameById } from '../../../redux/GamesSlice'; import { systemBlue } from '../../constants'; @@ -91,6 +92,7 @@ const GameHeader: React.FunctionComponent = ({ navigation }) => { + } headerCenter={<> diff --git a/src/components/ScoreLog/PlayerNameColumn.tsx b/src/components/ScoreLog/PlayerNameColumn.tsx index cbff3d92..16055f97 100644 --- a/src/components/ScoreLog/PlayerNameColumn.tsx +++ b/src/components/ScoreLog/PlayerNameColumn.tsx @@ -27,7 +27,7 @@ const PlayerNameColumn: React.FunctionComponent = ({ navigation, disabled ).sort((a, b) => currentGame.playerIds.indexOf(a.id) - currentGame.playerIds.indexOf(b.id)); return ( - { + { if (disabled) return; await analytics().logEvent('edit_game', { @@ -39,7 +39,7 @@ const PlayerNameColumn: React.FunctionComponent = ({ navigation, disabled   {players.map((player, index) => ( diff --git a/src/screens/GameScreen.tsx b/src/screens/GameScreen.tsx index 3a0102c4..9dbb5fcb 100644 --- a/src/screens/GameScreen.tsx +++ b/src/screens/GameScreen.tsx @@ -1,16 +1,15 @@ -import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; -import { View, StyleSheet, LayoutChangeEvent, Text } from 'react-native'; +import React, { useCallback, useEffect, useState } from 'react'; +import { View, StyleSheet, LayoutChangeEvent } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { getContrastRatio } from 'colorsheet'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { ParamListBase } from '@react-navigation/native'; -import BottomSheet, { BottomSheetScrollView } from '@gorhom/bottom-sheet'; import { useAppSelector } from '../../redux/hooks'; import PlayerTile from '../components/PlayerTile'; -import Rounds from '../components/Rounds'; import { selectGameById } from '../../redux/GamesSlice'; -import { systemBlue } from '../constants'; +import GameBottomSheet, { bottomSheetHeight } from '../components/GameBottomSheet'; + interface Props { navigation: NativeStackNavigationProp; @@ -93,25 +92,22 @@ const ScoreBoardScreen: React.FunctionComponent = ({ navigation }) => { return dims; }; - // ref - const bottomSheetRef = useRef(null); - - // variables - const snapPoints = useMemo(() => [73, '60%', '100%'], []); + const [windowHeight, setWindowHeight] = useState(0); - // callbacks - const handleSheetChanges = useCallback((index: number) => { - console.log('handleSheetChanges', index); - }, []); - - const handleSnapPress = useCallback((index: number) => { - bottomSheetRef.current?.snapToIndex(index); + const onLayout = useCallback((event: LayoutChangeEvent) => { + const { height } = event.nativeEvent.layout; + setWindowHeight(height); }, []); return ( - - + + {playerIds.map((id, index) => ( width != null && height != null && rows != 0 && cols != 0 && = ({ navigation }) => { /> ))} - - - - - - - handleSnapPress(1)}> - {currentGame.title} - - navigation.navigate('Settings')}> - Edit - - - - - Tap on a column to set the current round. - - - - + {!fullscreen && + + } ); @@ -168,7 +140,6 @@ const styles = StyleSheet.create({ flexDirection: 'row', maxWidth: '100%', backgroundColor: '#000000', - paddingBottom: 75, }, contentContainer: { flex: 1, diff --git a/src/screens/ShareScreen.tsx b/src/screens/ShareScreen.tsx index 694b7477..3ab2d6d8 100644 --- a/src/screens/ShareScreen.tsx +++ b/src/screens/ShareScreen.tsx @@ -53,7 +53,7 @@ const ShareScreen: React.FunctionComponent = ({ navigation }) => { return ( + style={[styles.contentContainer, { height: 'auto' }]}> @@ -79,14 +79,14 @@ const ShareScreen: React.FunctionComponent = ({ navigation }) => { contentContainerStyle={{ backgroundColor: 'black', flexDirection: 'column', - padding: 10, + padding: 20, }} ref={roundsScrollViewEl}> - + {currentGame?.title} - + Created: {new Date(currentGame.dateCreated).toLocaleDateString()}   {new Date(currentGame.dateCreated).toLocaleTimeString()} @@ -105,11 +105,6 @@ const ShareScreen: React.FunctionComponent = ({ navigation }) => { ))} - - - Created with ScorePad - -