All files / src/app/settings accessibility.tsx

84.61% Statements 11/13
100% Branches 4/4
66.66% Functions 4/6
84.61% Lines 11/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156                                      6x                     6x   6x   6x 6x     6x 6x   6x                                                                             18x                                                               18x                                               1x                                      
import React, { useEffect } from "react";
import { StyleSheet, Text, View, Pressable } from "react-native";
import {
  useAccessibilitySettings,
  getFontSizeLabel,
  getFontWeightLabel,
  useAccessibleTypography,
  FONT_SIZE_OPTIONS,
  FONT_WEIGHT_OPTIONS,
} from "../../hooks/useAccessibilitySettings";
import { useTheme } from "../../hooks/useTheme";
import { SettingsScreenScaffold } from "../../components/settings/SettingsScreenScaffold";
import {
  SettingsCard,
  SettingsLabeledValueRow,
  SettingsSwitchRow,
} from "../../components/settings";
 
export default function SettingsAccessibility() {
  const { colors } = useTheme();
  const {
    colorBlindMode,
    wheelchairUser,
    fontSize,
    fontWeight,
    toggleColorBlindMode,
    toggleWheelchairUser,
    setFontSize,
    setFontWeight,
    hydrateFromStorage,
  } = useAccessibilitySettings();
 
  const { textStyle } = useAccessibleTypography();
 
  useEffect(() => {
    void hydrateFromStorage();
  }, [hydrateFromStorage]);
 
  const titleStyle = textStyle(16);
  const subtitleStyle = textStyle(13);
 
  return (
    <SettingsScreenScaffold
      title="Accessibility Settings"
      backLabelStyle={textStyle(17)}
      titleStyle={[textStyle(28), { marginBottom: 20 }]}
    >
      <SettingsCard marginBottom={14}>
        <SettingsSwitchRow
          title="I use a wheelchair"
          subtitle="Prioritize accessible routes and elevator or ramp options"
          value={wheelchairUser}
          onValueChange={toggleWheelchairUser}
          titleStyle={titleStyle}
          subtitleStyle={subtitleStyle}
        />
      </SettingsCard>
 
      <SettingsCard marginBottom={14}>
        <SettingsSwitchRow
          title="Color Blind Mode"
          subtitle="Adjust colors for better visibility"
          value={colorBlindMode}
          onValueChange={toggleColorBlindMode}
          titleStyle={titleStyle}
          subtitleStyle={subtitleStyle}
        />
      </SettingsCard>
 
      <SettingsCard marginBottom={14}>
        <SettingsLabeledValueRow
          title="Font Size"
          subtitle="Make text larger throughout the app"
          valueLabel={getFontSizeLabel(fontSize)}
          titleStyle={titleStyle}
          subtitleStyle={subtitleStyle}
          valueStyle={textStyle(14)}
        />
        <View style={styles.sliderRow}>
          {FONT_SIZE_OPTIONS.map((option) => (
            <Pressable
              key={option}
              style={[
                styles.sliderDot,
                { backgroundColor: colors.border },
                fontSize === option && [
                  styles.sliderDotActive,
                  { backgroundColor: colors.primary },
                ],
              ]}
              onPress={() => setFontSize(option)}
            />
          ))}
        </View>
        <Text
          style={[styles.previewText, textStyle(16), { color: colors.primary }]}
        >
          This is how text will look
        </Text>
      </SettingsCard>
 
      <SettingsCard marginBottom={14}>
        <SettingsLabeledValueRow
          title="Text Weight"
          subtitle="Adjust how bold text appears"
          valueLabel={getFontWeightLabel(fontWeight)}
          titleStyle={titleStyle}
          subtitleStyle={subtitleStyle}
          valueStyle={textStyle(14)}
        />
        <View style={styles.sliderRow}>
          {FONT_WEIGHT_OPTIONS.map((option) => (
            <Pressable
              key={option}
              style={[
                styles.sliderDot,
                { backgroundColor: colors.border },
                fontWeight === option && [
                  styles.sliderDotActive,
                  { backgroundColor: colors.primary },
                ],
              ]}
              onPress={() => setFontWeight(option)}
            />
          ))}
        </View>
        <Text
          style={[styles.previewText, textStyle(15), { color: colors.primary }]}
        >
          Bold preview text
        </Text>
      </SettingsCard>
    </SettingsScreenScaffold>
  );
}
 
const styles = StyleSheet.create({
  sliderRow: {
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "space-between",
    marginTop: 12,
    paddingHorizontal: 8,
  },
  sliderDot: {
    width: 18,
    height: 18,
    borderRadius: 9,
  },
  sliderDotActive: {},
  previewText: {
    marginTop: 8,
    fontSize: 14,
  },
});