Skip to content

Commit 96bca50

Browse files
authored
Merge pull request #7 from jurevans/develop
Topbar titles, animation
2 parents 922ffba + 216ee11 commit 96bca50

File tree

12 files changed

+132
-25
lines changed

12 files changed

+132
-25
lines changed

src/apollo/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const client = new ApolloClient({
2222
link: concat(authMiddleware, link),
2323
cache: new InMemoryCache({
2424
typePolicies: {
25+
FeedInfo: {
26+
keyFields: FeedInfo => `${FeedInfo.__typename}:${FeedInfo.feedIndex}`,
27+
},
2528
Stop: {
2629
keyFields: Stop =>
2730
`${Stop.__typename}:${Stop.feedIndex}:${Stop.stopId}`,

src/apollo/fragments.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import { gql } from '@apollo/client';
22

3+
export const FEED_FIELDS = gql`
4+
fragment FeedFields on FeedInfo {
5+
feedIndex
6+
feedPublisherName
7+
}
8+
`;
9+
310
export const STOP_FIELDS = gql`
411
fragment StopFields on Stop {
512
feedIndex
613
stopId
714
stopName
15+
parentStation
816
geom {
917
coordinates
1018
}

src/apollo/queries.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { gql } from '@apollo/client';
2-
import { ROUTE_FIELDS, STOP_FIELDS, TRIP_FIELDS } from './fragments';
2+
import {
3+
FEED_FIELDS,
4+
ROUTE_FIELDS,
5+
STOP_FIELDS,
6+
TRIP_FIELDS,
7+
} from './fragments';
38

49
export const GET_FEEDS = gql`
10+
${FEED_FIELDS}
511
query GetFeeds {
612
feeds {
7-
feedIndex
8-
feedPublisherName
13+
...FeedFields
914
}
1015
}
1116
`;

src/components/Map.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { FC } from 'react';
22
import { GestureResponderEvent, StyleSheet } from 'react-native';
33
import MapboxGL, { RegionPayload } from '@react-native-mapbox-gl/maps';
4-
import { Feature, Point, Position } from '@turf/helpers';
4+
import { Feature, Point, Position } from '@turf/turf';
55
import { MAPBOX_ACCESS_TOKEN, MAPBOX_STYLE_URL } from '@env';
66

77
type Props = {

src/components/Stop.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React, { FC } from 'react';
22
import MapboxGL, { CircleLayerStyle } from '@react-native-mapbox-gl/maps';
3-
import * as turf from '@turf/turf';
3+
import { point, Position } from '@turf/turf';
44
import { StopTimeCallback } from './StopTime';
55

66
type Props = {
77
feedIndex: number;
88
tripId: string;
99
stopId: string;
10-
coordinates: turf.Position;
10+
coordinates: Position;
1111
color?: string;
1212
isActive?: boolean;
1313
aboveLayerId: string;
@@ -44,12 +44,12 @@ const Stop: FC<Props> = ({
4444
aboveLayerId,
4545
onPress,
4646
}) => {
47-
const point = turf.point(coordinates);
47+
const shape = point(coordinates);
4848
return (
4949
<MapboxGL.ShapeSource
5050
id={`shape-source-${feedIndex}:${stopId}`}
5151
key={`${stopId}`}
52-
shape={point}
52+
shape={shape}
5353
onPress={() => onPress({ feedIndex, tripId, stopId })}>
5454
<MapboxGL.CircleLayer
5555
id={`circle-layer-${feedIndex}:${stopId}`}

src/components/TripShape.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import MapboxGL, { LineLayerStyle } from '@react-native-mapbox-gl/maps';
2-
import * as turf from '@turf/turf';
3-
import { Position } from '@turf/turf';
2+
import { lineString, Position } from '@turf/turf';
43
import React, { FC } from 'react';
54

65
type Props = {
@@ -23,10 +22,9 @@ const TripShape: FC<Props> = ({
2322
color,
2423
coordinates = [],
2524
}) => {
26-
const lineString = turf.lineString(coordinates);
27-
25+
const shape = lineString(coordinates);
2826
return (
29-
<MapboxGL.ShapeSource id={shapeSourceId} shape={lineString}>
27+
<MapboxGL.ShapeSource id={shapeSourceId} shape={shape}>
3028
<MapboxGL.LineLayer id={layerId} style={getLineStyles(color)} />
3129
</MapboxGL.ShapeSource>
3230
);

src/interfaces/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface IStop {
1717
feedIndex: number;
1818
stopId: string;
1919
stopName: string;
20+
parentStation: string;
2021
geom: GeoJSON.Point;
2122
}
2223

src/navigation/roots.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Navigation } from 'react-native-navigation';
2+
import { Dimensions } from 'react-native';
23
import { Screens } from './screens';
34
import registerScreens from './registerScreens';
45

@@ -25,6 +26,28 @@ export const pushTabbedApp = () => {
2526
bottomTab: {
2627
text: 'Dashboard',
2728
},
29+
animations: {
30+
push: {
31+
content: {
32+
translationX: {
33+
from: Dimensions.get('window').width,
34+
to: 0,
35+
duration: 300,
36+
interpolation: { type: 'accelerate' },
37+
},
38+
},
39+
},
40+
pop: {
41+
content: {
42+
translationX: {
43+
from: 0,
44+
to: Dimensions.get('window').width,
45+
duration: 300,
46+
interpolation: { type: 'decelerate' },
47+
},
48+
},
49+
},
50+
},
2851
},
2952
},
3053
},

src/screens/map/MapScreen.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import React, { FC, useCallback, useEffect, useState } from 'react';
1+
import React, { FC, useCallback, useContext, useEffect, useState } from 'react';
22
import { View } from 'react-native';
33
import { gql, useQuery, useApolloClient } from '@apollo/client';
44
import { Feature, Point, Position } from '@turf/turf';
55
import { RegionPayload } from '@react-native-mapbox-gl/maps';
6+
import { Navigation } from 'react-native-navigation';
7+
import { NavigationContext } from 'react-native-navigation-hooks';
68
import { useAppDispatch, useAppSelector } from 'store/hooks';
79
import Map from 'components/Map';
810
import TripShape from 'components/TripShape';
@@ -13,7 +15,6 @@ import { setActiveStop } from 'slices/stops';
1315
import { GET_SHAPE } from 'apollo/queries';
1416
import { ROUTE_FIELDS, STOP_FIELDS, TRIP_FIELDS } from 'apollo/fragments';
1517
import { IRoute, IShape, IStop, IStopTime, ITrip } from 'interfaces';
16-
1718
import styles from './styles';
1819

1920
const DEFAULT_COORD: Position = [-73.94594865587045, 40.7227534777328];
@@ -28,6 +29,7 @@ const MapScreen: FC = () => {
2829
const { activeStop } = useAppSelector(state => state.stops);
2930
const dispatch = useAppDispatch();
3031
const client = useApolloClient();
32+
const { componentId = '' } = useContext(NavigationContext);
3133

3234
const [isMarkerVisible, setMarkerVisible] = useState(true);
3335
const [cameraState, setCameraState] = useState({
@@ -70,12 +72,20 @@ const MapScreen: FC = () => {
7072
});
7173

7274
useEffect(() => {
75+
Navigation.mergeOptions(componentId, {
76+
topBar: {
77+
title: {
78+
text: stop?.stopName,
79+
},
80+
},
81+
});
82+
7383
setCameraState(state => ({
7484
...state,
7585
centerCoordinate: stop?.geom.coordinates || DEFAULT_COORD,
7686
zoomLevel: STOP_ZOOM,
7787
}));
78-
}, [stop]);
88+
}, [componentId, stop]);
7989

8090
const onStopPress = useCallback<StopTimeCallback>(
8191
({ stopId, tripId, feedIndex }) => {

src/screens/routes/RoutesScreen.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,55 @@
1-
import React, { FC } from 'react';
1+
import React, { FC, useContext, useEffect } from 'react';
22
import {
33
FlatList,
44
ListRenderItemInfo,
55
Text,
66
TouchableOpacity,
77
View,
88
} from 'react-native';
9-
import { useNavigation } from 'react-native-navigation-hooks';
10-
import { useQuery } from '@apollo/client';
9+
import { Navigation } from 'react-native-navigation';
10+
import {
11+
NavigationContext,
12+
useNavigation,
13+
} from 'react-native-navigation-hooks';
14+
import { gql, useApolloClient, useQuery } from '@apollo/client';
1115
import { GET_ROUTES } from 'apollo/queries';
16+
import { FEED_FIELDS } from 'apollo/fragments';
1217
import { Screens } from 'navigation/screens';
13-
import { IRoute } from 'interfaces';
14-
import styles from './styles';
1518
import Error from 'components/Error';
1619
import Loading from 'components/Loading';
20+
import { IFeed, IRoute } from 'interfaces';
21+
import styles from './styles';
1722

1823
type Props = {
1924
feedIndex: number;
2025
};
2126

2227
const RoutesScreen: FC<Props> = ({ feedIndex }) => {
28+
const client = useApolloClient();
2329
const { push } = useNavigation();
30+
const { componentId = '' } = useContext(NavigationContext);
31+
32+
// Retrieve trip fragment from cache
33+
const feed: IFeed | null = client.readFragment({
34+
id: `FeedInfo:${feedIndex}`,
35+
fragment: gql`
36+
${FEED_FIELDS}
37+
`,
38+
});
39+
40+
const { feedPublisherName } = feed || {};
41+
42+
useEffect(() => {
43+
if (feedPublisherName) {
44+
Navigation.mergeOptions(componentId, {
45+
topBar: {
46+
title: {
47+
text: `${feedPublisherName}`,
48+
},
49+
},
50+
});
51+
}
52+
}, [componentId, feedPublisherName]);
2453

2554
interface RouteVars {
2655
feedIndex: number;

0 commit comments

Comments
 (0)