Skip to content

Commit

Permalink
Creating a custom Callout on Near You Map for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
steniowagner committed Feb 6, 2019
1 parent f2c816b commit 76a6b05
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/screens/near-you/components/NearYou.js
Expand Up @@ -11,7 +11,7 @@ import Loading from '~/components/common/Loading';
import appStyles from '~/styles';

import RestaurantsList from './restaurants-list';
import Map from './Map';
import Map from './map';

const Container = styled(View)`
flex: 1;
Expand Down
32 changes: 32 additions & 0 deletions src/components/screens/near-you/components/map/AndroidCallout.js
@@ -0,0 +1,32 @@
// @flow

import React from 'react';
import { View, Text } from 'react-native';
import styled from 'styled-components';

const Wrapper = styled(View)`
flex: 1;
flex-direction: row;
justify-content: center;
align-items: center;
padding: ${({ theme }) => theme.metrics.smallSize}px;
`;

const RestaurantName = styled(Text)`
color: ${({ theme }) => theme.colors.darkText};
font-size: ${({ theme }) => theme.metrics.getWidthFromDP('5.5%')}px;
font-family: CircularStd-Bold;
text-align: center;
`;

type Props = {
restaurantName: string,
};

const AndroidCallout = ({ restaurantName }: Props): Object => (
<Wrapper>
<RestaurantName>{restaurantName}</RestaurantName>
</Wrapper>
);

export default AndroidCallout;
@@ -1,16 +1,25 @@
// @flow

import React, { Component, Fragment } from 'react';
import MapView, { Marker } from 'react-native-maps';
import { Platform, View } from 'react-native';

import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import MapView, { Marker, Callout } from 'react-native-maps';
import styled from 'styled-components';

import AndroidCallout from './AndroidCallout';

const MapContainer = styled(MapView)`
width: 100%;
height: 100%;
`;

const MarkerWrapper = styled(View)`
flex: 1;
justify-content: center;
align-items: center;
`;

const CustomMarker = styled(Icon).attrs(({ name }) => ({
size: 30,
name,
Expand Down Expand Up @@ -102,9 +111,20 @@ class Map extends Component<Props, {}> {
title={name}
key={id}
>
<CustomMarker
name={iconName}
/>
<MarkerWrapper>
<CustomMarker
name={iconName}
/>
{Platform.OS === 'android' && (
<Callout
style={{ flex: 1, position: 'relative' }}
>
<AndroidCallout
restaurantName={name}
/>
</Callout>
)}
</MarkerWrapper>
</Marker>
);
})}
Expand Down

0 comments on commit 76a6b05

Please sign in to comment.