-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Add optional directional arrow to map (#914)
* feat: Added directional Arrow * chore: build translations * chore:clean up * chore: PR clean up * fix: change constant name Co-authored-by: Andrew Chou <andrewchou@fastmail.com> * fix: type with translations Co-authored-by: Andrew Chou <andrewchou@fastmail.com>
- Loading branch information
Showing
10 changed files
with
140 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from "react"; | ||
import SettingsContext, { SettingsState } from "../context/SettingsContext"; | ||
|
||
export default function useSettingsValue<K extends keyof SettingsState>( | ||
key: K | ||
): SettingsState[K] { | ||
const [state] = React.useContext(SettingsContext); | ||
return state[key]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useContext } from "react"; | ||
import { FormattedMessage, defineMessages } from "react-intl"; | ||
import { Switch } from "react-native"; | ||
import { NavigationStackScreenComponent } from "react-navigation-stack"; | ||
import SettingsContext from "../../context/SettingsContext"; | ||
import { DARK_BLUE, LIGHT_GREY } from "../../lib/styles"; | ||
|
||
import HeaderTitle from "../../sharedComponents/HeaderTitle"; | ||
import IconButton from "../../sharedComponents/IconButton"; | ||
import { BackIcon } from "../../sharedComponents/icons"; | ||
import { List, ListItem, ListItemText } from "../../sharedComponents/List"; | ||
|
||
const m = defineMessages({ | ||
mapSettingTitle: { | ||
id: "screens.Settings.MapSettings.mapSettingTitle", | ||
defaultMessage: "Map Settings", | ||
}, | ||
directionalArrow: { | ||
id: "screens.Settings.MapSettings.directionalArrow", | ||
defaultMessage: "Use Directional Arrow", | ||
}, | ||
batteryWarning: { | ||
id: "screens.Settings.MapSettings.batteryWarning", | ||
defaultMessage: "May drain battery faster", | ||
}, | ||
}); | ||
|
||
export const MapSettings: NavigationStackScreenComponent = () => { | ||
const [{ directionalArrow }, setSetting] = useContext(SettingsContext); | ||
return ( | ||
<List> | ||
<ListItem | ||
onPress={() => setSetting("directionalArrow", !directionalArrow)} | ||
> | ||
<ListItemText | ||
primary={<FormattedMessage {...m.directionalArrow} />} | ||
secondary={<FormattedMessage {...m.batteryWarning} />} | ||
/> | ||
<Switch | ||
trackColor={{ false: LIGHT_GREY }} | ||
thumbColor={directionalArrow ? DARK_BLUE : LIGHT_GREY} | ||
value={directionalArrow} | ||
/> | ||
</ListItem> | ||
</List> | ||
); | ||
}; | ||
|
||
MapSettings.navigationOptions = () => ({ | ||
headerTitle: () => ( | ||
<HeaderTitle style={{}}> | ||
<FormattedMessage {...m.mapSettingTitle} /> | ||
</HeaderTitle> | ||
), | ||
headerLeft: ({ onPress }) => | ||
onPress && ( | ||
<IconButton onPress={onPress}> | ||
<BackIcon /> | ||
</IconButton> | ||
), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import MapboxGL from "@react-native-mapbox-gl/maps"; | ||
import * as React from "react"; | ||
import useSettingsValue from "../../hooks/useSettingsValue"; | ||
|
||
interface UserLocationProps { | ||
visible: boolean; | ||
minDisplacement: number; | ||
} | ||
|
||
export const UserLocation = ({ | ||
visible, | ||
minDisplacement, | ||
}: UserLocationProps) => { | ||
const directionalArrow = useSettingsValue("directionalArrow"); | ||
|
||
return ( | ||
<MapboxGL.UserLocation | ||
visible={visible} | ||
minDisplacement={directionalArrow ? 1 : minDisplacement} | ||
showsUserHeadingIndicator={directionalArrow} | ||
/> | ||
); | ||
}; |