Skip to content

Commit

Permalink
feat: separate card settings section (#66)
Browse files Browse the repository at this point in the history
* feat: seperate card settings section

* feat: seperate card settings section
  • Loading branch information
gajjartejas committed Oct 17, 2023
1 parent 3f297d3 commit 43f40d6
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 55 deletions.
28 changes: 19 additions & 9 deletions app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@
},
"generalSetting": {
"title": "General",
"section1": {
"header": "General",
"row1": {
"title": "Swipe Card",
"subTitle": "Change card animation & duration"
}
},
"section2": {
"header": "Other",
"row1": {
"title": "Clear progress",
"subTitle": "Clear all progress",
"dialogTitle": "Clear app progress?",
"dialogSubTitle": "Are you sure you want to clear app progress?"
}
}
},
"swipeCardSetting": {
"title": "Swipe Card",
"section1": {
"header": "General",
"row1": {
Expand All @@ -95,15 +114,6 @@
"unit": "Second(s)"
}
}
},
"section2": {
"header": "Other",
"row1": {
"title": "Clear progress",
"subTitle": "Clear all progress",
"dialogTitle": "Clear app progress?",
"dialogSubTitle": "Are you sure you want to clear app progress?"
}
}
},
"cardAnimation": {
Expand Down
4 changes: 3 additions & 1 deletion app/navigation/HomeTabNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import LearnBySelectedChar from 'app/screens/HomeIntro/CharsIntro/LearnBySelecte
import LearnCharStrokeOrder from 'app/screens/HomeIntro/CharsIntro/LearnCharStrokeOrder';
import GeneralSetting from 'app/screens/Settings/GeneralSetting';
import CardAnimation from 'app/screens/Settings/CardAnimation';
import LearnCharAnimatedDrawing from 'app/screens/HomeIntro/CharsIntro/LearnCharAnimatedDrawing';
import SwipeCardSetting from 'app/screens/Settings/SwipeCardSetting';

//App Modules
import { HomeTabsNavigatorParams, LoggedInTabNavigatorParams } from 'app/navigation/types';
import { AppTheme } from 'app/models/theme';
import LearnCharAnimatedDrawing from 'app/screens/HomeIntro/CharsIntro/LearnCharAnimatedDrawing';

const Tab = createMaterialBottomTabNavigator<HomeTabsNavigatorParams>();

Expand Down Expand Up @@ -102,6 +103,7 @@ const LoggedInTabNavigator = () => {
<LoggedInStack.Screen name="LearnCharInfo" component={LearnCharInfo} options={{ headerShown: false }} />
<LoggedInStack.Screen name="LearnCharsCard" component={LearnCharsCard} options={{ headerShown: false }} />
<LoggedInStack.Screen name="GeneralSetting" component={GeneralSetting} options={{ headerShown: false }} />
<LoggedInStack.Screen name="SwipeCardSetting" component={SwipeCardSetting} options={{ headerShown: false }} />
<LoggedInStack.Screen name="CardAnimation" component={CardAnimation} options={{ headerShown: false }} />
<LoggedInStack.Group screenOptions={{ presentation: 'modal' }}>
<LoggedInStack.Screen
Expand Down
2 changes: 2 additions & 0 deletions app/navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface GujaratiScriptIntroParams {
color: string;
}
export interface GeneralSettingParams {}
export interface SwipeCardSettingParams {}
export interface MoreAppsParams {}
export interface SettingsParams {}
export interface LicenseTypes {}
Expand Down Expand Up @@ -93,6 +94,7 @@ export type LoggedInTabNavigatorParams = {
LearnCharStrokeOrder: LearnCharStrokeOrderParams;
LearnCharAnimatedDrawing: LearnCharAnimatedDrawingParams;
CardAnimation: CardAnimationParams;
SwipeCardSetting: SwipeCardSettingParams;
};

export type HomeTabsNavigatorParams = {
Expand Down
5 changes: 3 additions & 2 deletions app/screens/HomeIntro/LearnCharsCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ const LearnCharsCard = ({ navigation, route }: Props) => {
}, [color, isRandomMode, learnMode, navigation, onlyInclude, type]);

const onPressSetting = useCallback(() => {
navigation.push('GeneralSetting', {});
navigation.push('SwipeCardSetting', {});
}, [navigation]);

const onCloseRandomDialog = useCallback(() => {
Expand All @@ -438,6 +438,7 @@ const LearnCharsCard = ({ navigation, route }: Props) => {
<Components.AppBaseView edges={['bottom', 'left', 'right']} style={styles.safeArea}>
{!practiceMode && (
<View
pointerEvents={autoSwiping ? 'none' : 'auto'}
onLayout={e => {
const { width: w, height: h } = e.nativeEvent.layout;
setWidth(w > h ? h : w);
Expand All @@ -450,7 +451,7 @@ const LearnCharsCard = ({ navigation, route }: Props) => {
onSwipe={onSwipe}
swipeRequirementType={'position'}
swipeThreshold={100}
preventSwipe={autoSwiping ? ['left', 'right', 'up', 'bottom'] : []}>
preventSwipe={[]}>
<TouchableRipple rippleColor={`${colors.primary}20`} onPress={() => onPressCard(item, index)}>
<Animated.View
entering={FadeInDown.duration(index % GROUP_COUNT === 1 ? 0 : 1000).easing(
Expand Down
37 changes: 2 additions & 35 deletions app/screens/Settings/GeneralSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { LoggedInTabNavigatorParams } from 'app/navigation/types';
import useOtherStatics from 'app/realm/crud/otherStatics';
import useLargeScreenMode from 'app/hooks/useLargeScreenMode';
import AppHeader from 'app/components/AppHeader';
import useCardAnimationConfigStore from 'app/store/cardAnimationConfig';

//Params
type Props = NativeStackScreenProps<LoggedInTabNavigatorParams, 'GeneralSetting'>;
Expand All @@ -36,12 +35,9 @@ const GeneralSetting = ({ navigation }: Props) => {
const { clearAllData: clearAllChartData } = useChartStatics();
const { clearAllData: clearAllOtherData } = useOtherStatics();
const largeScreenMode = useLargeScreenMode();
const cardAutoSwipeDurationSeconds = useCardAnimationConfigStore(store => store.cardAutoSwipeDurationSeconds);
const setCardAutoSwipeDurationSeconds = useCardAnimationConfigStore(store => store.setCardAutoSwipeDurationSeconds);

//States
const [clearProgressAlertVisible, setClearProgressAlertVisible] = useState(false);
const [autoSwipeCardModeAlertVisible, setAutoSwipeCardModeAlertVisible] = useState(false);

const [apps] = useState<ISettingSection[]>([
{
Expand All @@ -50,20 +46,12 @@ const GeneralSetting = ({ navigation }: Props) => {
items: [
{
id: 0,
iconName: 'animation-play',
iconName: 'cards',
iconType: 'material-community',
title: t('generalSetting.section1.row1.title'),
description: t('generalSetting.section1.row1.subTitle'),
route: 'CardAnimation',
},
{
id: 1,
iconName: 'gesture-swipe',
iconType: 'material-community',
title: t('generalSetting.section1.row2.title'),
description: t('generalSetting.section1.row2.subTitle'),
route: 'CardAnimation',
},
],
},
{
Expand All @@ -89,10 +77,7 @@ const GeneralSetting = ({ navigation }: Props) => {
const onPressAppearanceOption = (item: ISettingSection, index: number, subItem: ISettingItem, subIndex: number) => {
switch (true) {
case index === 0 && subIndex === 0:
navigation.navigate('CardAnimation', {});
break;
case index === 0 && subIndex === 1:
setAutoSwipeCardModeAlertVisible(true);
navigation.navigate('SwipeCardSetting', {});
break;
case index === 1 && subIndex === 0:
setClearProgressAlertVisible(true);
Expand All @@ -108,11 +93,6 @@ const GeneralSetting = ({ navigation }: Props) => {
clearAllOtherData();
};

const onPressConfirmCardAutoSwipeDuration = (value: number) => {
setCardAutoSwipeDurationSeconds(value);
setAutoSwipeCardModeAlertVisible(false);
};

return (
<View style={[styles.container, { backgroundColor: colors.background }]}>
<AppHeader
Expand Down Expand Up @@ -168,19 +148,6 @@ const GeneralSetting = ({ navigation }: Props) => {
onPressConfirm={onClearAllData}
onPressCancel={() => setClearProgressAlertVisible(false)}
/>
<Components.AppSliderDialog
title={t('generalSetting.section1.row2.cardAutoSwipeDurationAlert.title')}
description={t('generalSetting.section1.row2.cardAutoSwipeDurationAlert.desc')}
visible={autoSwipeCardModeAlertVisible}
cancelText={t('general.cancel')}
confirmText={t('general.ok')}
onPressConfirm={onPressConfirmCardAutoSwipeDuration}
onPressCancel={() => setAutoSwipeCardModeAlertVisible(false)}
range={[1, 10]}
step={1}
unit={t('generalSetting.section1.row2.cardAutoSwipeDurationAlert.unit')}
value={cardAutoSwipeDurationSeconds}
/>
</View>
);
};
Expand Down
148 changes: 148 additions & 0 deletions app/screens/Settings/SwipeCardSetting/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import React, { useState } from 'react';
import { ScrollView, View } from 'react-native';

//ThirdParty
import { useTranslation } from 'react-i18next';
import { Divider, List, useTheme } from 'react-native-paper';
import { NativeStackScreenProps } from '@react-navigation/native-stack';
import Icon from 'react-native-easy-icon';

//App modules
import styles from './styles';

//ThirdParty

//App Modules
import { ISettingItem, ISettingSection } from 'app/models/viewModels/settingItem';
import Components from 'app/components';
import { LoggedInTabNavigatorParams } from 'app/navigation/types';
import useLargeScreenMode from 'app/hooks/useLargeScreenMode';
import AppHeader from 'app/components/AppHeader';
import useCardAnimationConfigStore from 'app/store/cardAnimationConfig';

//Params
type Props = NativeStackScreenProps<LoggedInTabNavigatorParams, 'SwipeCardSetting'>;

const SwipeCardSetting = ({ navigation }: Props) => {
//Refs

//Constants
const { t } = useTranslation();
const { colors } = useTheme();
const largeScreenMode = useLargeScreenMode();
const cardAutoSwipeDurationSeconds = useCardAnimationConfigStore(store => store.cardAutoSwipeDurationSeconds);
const setCardAutoSwipeDurationSeconds = useCardAnimationConfigStore(store => store.setCardAutoSwipeDurationSeconds);

//States
const [autoSwipeCardModeAlertVisible, setAutoSwipeCardModeAlertVisible] = useState(false);

const [apps] = useState<ISettingSection[]>([
{
id: 0,
title: t('swipeCardSetting.section1.header'),
items: [
{
id: 0,
iconName: 'animation-play',
iconType: 'material-community',
title: t('swipeCardSetting.section1.row1.title'),
description: t('swipeCardSetting.section1.row1.subTitle'),
route: 'CardAnimation',
},
{
id: 1,
iconName: 'gesture-swipe',
iconType: 'material-community',
title: t('swipeCardSetting.section1.row2.title'),
description: t('swipeCardSetting.section1.row2.subTitle'),
route: 'CardAnimation',
},
],
},
]);

const onGoBack = () => {
navigation.pop();
};

const onPressAppearanceOption = (item: ISettingSection, index: number, subItem: ISettingItem, subIndex: number) => {
switch (true) {
case index === 0 && subIndex === 0:
navigation.navigate('CardAnimation', {});
break;
case index === 0 && subIndex === 1:
setAutoSwipeCardModeAlertVisible(true);
break;
default:
}
};

const onPressConfirmCardAutoSwipeDuration = (value: number) => {
setCardAutoSwipeDurationSeconds(value);
setAutoSwipeCardModeAlertVisible(false);
};

return (
<View style={[styles.container, { backgroundColor: colors.background }]}>
<AppHeader
showBackButton={true}
onPressBackButton={onGoBack}
title={t('swipeCardSetting.title')}
style={{ backgroundColor: colors.background }}
/>

<View style={styles.safeArea}>
<ScrollView>
<View style={[styles.listContainer, largeScreenMode && styles.cardTablet]}>
{apps.map((item, index) => {
return (
<View key={item.id.toString()}>
<List.Subheader style={[styles.listSubHeader, { color: colors.primary }]}>
{item.title}
</List.Subheader>
{item.items.map((subItem, subIndex) => {
return (
<List.Item
key={subItem.id.toString()}
titleStyle={{ color: colors.onSurface }}
descriptionStyle={{ color: `${colors.onSurface}88` }}
onPress={() => onPressAppearanceOption(item, index, subItem, subIndex)}
title={subItem.title}
description={subItem.description}
left={() => (
<Icon
style={styles.listItemIcon}
type={subItem.iconType}
name={subItem.iconName}
color={`${colors.onSurface}88`}
size={24}
/>
)}
/>
);
})}
<Divider />
</View>
);
})}
</View>
</ScrollView>
</View>
<Components.AppSliderDialog
title={t('swipeCardSetting.section1.row2.cardAutoSwipeDurationAlert.title')}
description={t('swipeCardSetting.section1.row2.cardAutoSwipeDurationAlert.desc')}
visible={autoSwipeCardModeAlertVisible}
cancelText={t('general.cancel')}
confirmText={t('general.ok')}
onPressConfirm={onPressConfirmCardAutoSwipeDuration}
onPressCancel={() => setAutoSwipeCardModeAlertVisible(false)}
range={[1, 10]}
step={1}
unit={t('swipeCardSetting.section1.row2.cardAutoSwipeDurationAlert.unit')}
value={cardAutoSwipeDurationSeconds}
/>
</View>
);
};

export default SwipeCardSetting;
26 changes: 26 additions & 0 deletions app/screens/Settings/SwipeCardSetting/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { StyleSheet } from 'react-native';

const styles = StyleSheet.create({
container: {
flex: 1,
},
headerStyle: {},
safeArea: {
flex: 1,
},
scrollView: {},
subView: {
marginHorizontal: 32,
},
listSubHeader: { marginLeft: 48 },
listItemIcon: { alignSelf: 'center', marginHorizontal: 12 },
cardTablet: {
width: '70%',
alignSelf: 'center',
},
listContainer: {
paddingBottom: 8,
},
});

export default styles;
Loading

0 comments on commit 43f40d6

Please sign in to comment.