Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WebView component for external services #14

Merged
merged 1 commit into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/components/Button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import PropTypes from 'prop-types';
import React from 'react';
import { StyleSheet } from 'react-native';
import { Button as RNEButton } from 'react-native-elements';

import { colors } from '../config';

export const Button = ({ title, onPress }) => {
return (
<RNEButton
type="outline"
onPress={onPress}
title={title}
titleStyle={styles.titleStyle}
buttonStyle={styles.buttonStyle}
/>
);
};

const styles = StyleSheet.create({
titleStyle: {
color: colors.primary,
fontFamily: 'titillium-web-bold'
},
buttonStyle: {
borderColor: colors.primary
}
});

Button.propTypes = {
title: PropTypes.string.isRequired,
onPress: PropTypes.func.isRequired
};
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './Button';
export * from './CardList';
export * from './DiagonalGradient';
export * from './HtmlView';
Expand Down
8 changes: 7 additions & 1 deletion src/navigation/AppStackNavigator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createStackNavigator } from 'react-navigation';

import { DetailScreen, HomeScreen, HtmlScreen, IndexScreen } from '../screens';
import { DetailScreen, HomeScreen, HtmlScreen, IndexScreen, WebScreen } from '../screens';
import { defaultStackNavigatorConfig } from './defaultStackNavigatorConfig';

import { texts } from '../config';
Expand Down Expand Up @@ -30,6 +30,12 @@ const AppStackNavigator = createStackNavigator(
navigationOptions: (props) => ({
title: props.navigation.getParam('title', '')
})
},
Web: {
screen: WebScreen,
navigationOptions: (props) => ({
title: props.navigation.getParam('title', '')
})
}
},
defaultStackNavigatorConfig('Home')
Expand Down
18 changes: 17 additions & 1 deletion src/screens/HtmlScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ActivityIndicator, ScrollView, StyleSheet, TouchableOpacity, View } fro
import { Query } from 'react-apollo';

import { colors, normalize } from '../config';
import { HtmlView, Icon, Wrapper } from '../components';
import { Button, HtmlView, Icon, Wrapper } from '../components';
import { trimNewLines } from '../helpers';
import { GET_PUBLIC_HTML_FILE } from '../queries';
import { arrowLeft } from '../icons';
Expand All @@ -25,6 +25,8 @@ export class HtmlScreen extends React.Component {
render() {
const { navigation } = this.props;
const queryVariables = navigation.getParam('queryVariables', '');
const title = navigation.getParam('title', '');
const webUrl = navigation.getParam('webUrl', '');

if (!queryVariables || !queryVariables.name) return null;

Expand All @@ -49,6 +51,20 @@ export class HtmlScreen extends React.Component {
<ScrollView>
<Wrapper>
<HtmlView html={trimNewLines(data.publicHtmlFile.content)} />
{!!webUrl && (
<Button
title={`${title} öffnen`}
onPress={() =>
navigation.navigate({
routeName: 'Web',
params: {
title,
webUrl
}
})
}
/>
)}
</Wrapper>
</ScrollView>
);
Expand Down
55 changes: 55 additions & 0 deletions src/screens/WebScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import PropTypes from 'prop-types';
import React from 'react';
import { ActivityIndicator, StyleSheet, TouchableOpacity, View, WebView } from 'react-native';

import { colors, normalize } from '../config';
import { Icon } from '../components';
import { arrowLeft } from '../icons';

export class WebScreen extends React.PureComponent {
static navigationOptions = ({ navigation }) => {
return {
headerLeft: (
<View>
<TouchableOpacity onPress={() => navigation.goBack()}>
<Icon icon={arrowLeft(colors.lightestText)} style={styles.icon} />
</TouchableOpacity>
</View>
)
};
};

render() {
const { navigation } = this.props;
const webUrl = navigation.getParam('webUrl', '');

if (!webUrl) return null;

return (
<WebView
source={{ uri: webUrl }}
startInLoadingState
renderLoading={() => (
<View style={styles.loadingContainer}>
<ActivityIndicator />
</View>
)}
/>
);
}
}

const styles = StyleSheet.create({
icon: {
paddingHorizontal: normalize(14)
},
loadingContainer: {
alignItems: 'center',
flex: 1,
justifyContent: 'center'
}
});

WebScreen.propTypes = {
navigation: PropTypes.object.isRequired
};
1 change: 1 addition & 0 deletions src/screens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './DetailScreen';
export * from './HomeScreen';
export * from './HtmlScreen';
export * from './IndexScreen';
export * from './WebScreen';