Skip to content

Commit

Permalink
Merge pull request sap-labs-france#576 from sap-labs-france/charging_…
Browse files Browse the repository at this point in the history
…stations_radius

Charging stations radius
  • Loading branch information
LucasBrazi06 authored Dec 3, 2021
2 parents 6c68ed4 + e0ba4dd commit 9c4e5c7
Show file tree
Hide file tree
Showing 18 changed files with 951 additions and 4,751 deletions.
4,707 changes: 318 additions & 4,389 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"react-native-htmlview": "^0.16.0",
"react-native-localize": "^1.4.3",
"react-native-location": "^2.5.0",
"react-native-map-clustering": "^3.4.2",
"react-native-map-link": "^2.8.0",
"react-native-maps": "^0.29.3",
"react-native-modal": "^11.10.0",
Expand Down
1 change: 1 addition & 0 deletions src/components/fab/FabComponentStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function computeStyleSheet(): StyleSheet.NamedStyles<any> {
justifyContent: 'center',
bottom: 0,
right: 0,
marginTop: '14@s',
zIndex: 1,
elevation: 4,
backgroundColor: commonColor.primary,
Expand Down
22 changes: 15 additions & 7 deletions src/components/header/HeaderComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Icon } from 'native-base';
import React from 'react';
import { View, TouchableOpacity, Text, BackHandler } from 'react-native';
import { View, TouchableOpacity, Text } from 'react-native';

import FilterModalContainerComponent from '../../components/search/filter/containers/FilterModalContainerComponent';
import BaseProps from '../../types/BaseProps';
import { IconType } from '../../types/Icon';
import computeStyleSheet from './HeaderComponentStyles';
import { DrawerActions } from '@react-navigation/native';

Expand All @@ -24,7 +23,7 @@ interface State {

export interface HeaderAction {
onPress?: () => void;
renderIcon?: () => React.ReactElement;
renderAction?: () => React.ReactElement;
}

export default class HeaderComponent extends React.Component<Props, State> {
Expand Down Expand Up @@ -86,14 +85,23 @@ export default class HeaderComponent extends React.Component<Props, State> {
</TouchableOpacity>
)
)}
<Text numberOfLines={1} ellipsizeMode={'tail'} style={style.title}>
{title} {subTitle}
</Text>
</View>
<View style={style.titlesContainer}>
<View style={style.titleContainer}>
<Text numberOfLines={1} ellipsizeMode={'tail'} style={style.title}>
{title}
</Text>
</View>
<View>
<Text numberOfLines={1} style={style.subTitle}>
{subTitle}
</Text>
</View>
</View>
<View style={style.actionsContainer}>
{actions?.map((action, index) => (
<TouchableOpacity style={style.action} key={index} onPress={action.onPress}>
{action.renderIcon?.()}
{action.renderAction?.()}
</TouchableOpacity>
))}
{this.filterModalContainerComponent && (
Expand Down
28 changes: 22 additions & 6 deletions src/components/header/HeaderComponentStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function computeStyleSheet(): StyleSheet.NamedStyles<any> {
padding: '5@s',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-start',
margin: 0,
borderBottomWidth: 0,
borderTopWidth: 0,
Expand All @@ -23,7 +24,8 @@ export default function computeStyleSheet(): StyleSheet.NamedStyles<any> {
},
icon: {
color: commonColor.textColor,
fontSize: '20@s'
fontSize: '20@s',
paddingTop: '2@s'
},
leftIcon: {
marginLeft: '2.5%',
Expand All @@ -35,19 +37,33 @@ export default function computeStyleSheet(): StyleSheet.NamedStyles<any> {
leftHeader: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
flex: 1
justifyContent: 'flex-start'
},
titlesContainer: {
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
alignItems: 'flex-start',
justifyContent: 'flex-start'
},
titleContainer: {
maxWidth: '100%',
marginRight: '5@s'
},
title: {
color: commonColor.textColor,
fontSize: '17@s',
textAlign: 'left',
marginLeft: '2.5%',
flex: 1
width: '100%'
},
subTitle: {
width: '100%',
color: commonColor.textColor,
fontSize: '17@s',
textAlign: 'left',
},
actionsContainer: {
flexDirection: 'row',
marginRight: '2.5%',
marginLeft: '10@s'
},
action: {
Expand Down
69 changes: 69 additions & 0 deletions src/components/map/ClusterMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from 'react';
import MapView from 'react-native-map-clustering';
import MapCluster from './cluster/MapCluster';
import { Region } from 'react-native-maps';
import ChargingStation from '../../types/ChargingStation';
import Site from '../../types/Site';
import SiteArea from '../../types/SiteArea';
import Utils from '../../utils/Utils';
import ThemeManager from '../../custom-theme/ThemeManager';
import computeStyleSheet from './ClusterMapStyle';
import { View } from 'native-base';

interface State {}

type Localizable = ChargingStation | Site | SiteArea;

export interface Props<T> {
items: T[]
renderMarker: (item: T, index: number) => React.ReactElement;
initialRegion: Region;
onMapRegionChangeComplete: (region: Region) => void;
satelliteMap?: boolean;
}

export default class ClusterMap<T extends Localizable> extends React.Component<Props<T>, State> {
public props: Props<T>;
public state: State;
private darkMapTheme = require('../../utils/map/google-maps-night-style.json');

public constructor(props: Props<T>) {
super(props);
this.state = {
satelliteMap: false
}
}

public render() {
const { items, renderMarker, initialRegion, onMapRegionChangeComplete, satelliteMap } = this.props;
const commonColors = Utils.getCurrentCommonColor();
const isDarkModeEnabled = ThemeManager.getInstance()?.isThemeTypeIsDark();
const style = computeStyleSheet();
return (
<View style={style.map}>
{initialRegion && (
<MapView
customMapStyle={isDarkModeEnabled ? this.darkMapTheme : null}
style={style.map}
showsCompass={false}
showsUserLocation={true}
zoomControlEnabled={false}
toolbarEnabled={false}
spiralEnabled={true}
radius={5}
tracksViewChanges={false}
renderCluster={(cluster) => <MapCluster cluster={cluster} />}
spiderLineColor={commonColors.textColor}
mapType={satelliteMap ? 'satellite' : 'standard'}
initialRegion={initialRegion}
onRegionChangeComplete={onMapRegionChangeComplete}
>
{items.map((item, index) => (
renderMarker?.(item, index)
))}
</MapView>
)}
</View>
)
}
}
19 changes: 19 additions & 0 deletions src/components/map/ClusterMapStyle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import deepmerge from 'deepmerge';
import { StyleSheet } from 'react-native';
import ResponsiveStylesSheet from 'react-native-responsive-stylesheet';
import { ScaledSheet } from 'react-native-size-matters';

export default function computeStyleSheet(): StyleSheet.NamedStyles<any> {
const commonStyles = ScaledSheet.create({
map: {
width: '100%',
height: '100%'
}
});
const portraitStyles = {};
const landscapeStyles = {};
return ResponsiveStylesSheet.createOriented({
landscape: deepmerge(commonStyles, landscapeStyles) as StyleSheet.NamedStyles<any>,
portrait: deepmerge(commonStyles, portraitStyles) as StyleSheet.NamedStyles<any>
});
}
24 changes: 24 additions & 0 deletions src/components/map/cluster/MapCluster.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { Marker } from 'react-native-maps';
import { View } from 'native-base';
import { Text } from 'react-native';
import computeStyleSheet from './MapClusterStyle';

export interface Props {
cluster: any;
}

interface State {}

export default class MapCluster extends React.Component<Props, State> {

public render() {
const style = computeStyleSheet();
const { geometry, onPress, id, properties } = this.props?.cluster;
return (
<Marker onPress={onPress} tracksViewChanges={false} key={id} coordinate={{longitude: geometry.coordinates[0], latitude: geometry.coordinates[1]}}>
<View style={style.cluster}><Text>{properties?.point_count}</Text></View>
</Marker>
);
}
}
30 changes: 30 additions & 0 deletions src/components/map/cluster/MapClusterStyle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import deepmerge from 'deepmerge';
import { StyleSheet } from 'react-native';
import ResponsiveStylesSheet from 'react-native-responsive-stylesheet';
import { ScaledSheet } from 'react-native-size-matters';

import Utils from '../../../utils/Utils';

export default function computeStyleSheet(): StyleSheet.NamedStyles<any> {
const commonColor = Utils.getCurrentCommonColor();
const commonStyles = ScaledSheet.create({
cluster: {
backgroundColor: commonColor.listItemBackground,
padding: '10@s',
width: '50@s',
height: '50@s',
alignItems: 'center',
justifyContent: 'center',
borderRadius: '50@s',
borderWidth: 2,
borderColor: commonColor.mapClusterBorder,
zIndex: 1
}
});
const portraitStyles = {};
const landscapeStyles = {};
return ResponsiveStylesSheet.createOriented({
landscape: deepmerge(commonStyles, landscapeStyles) as StyleSheet.NamedStyles<any>,
portrait: deepmerge(commonStyles, portraitStyles) as StyleSheet.NamedStyles<any>
});
}
Loading

0 comments on commit 9c4e5c7

Please sign in to comment.