Improved web browser handling

This commit is contained in:
Arnaud Vergnet 2020-03-30 17:39:59 +02:00
parent 5bf1e7586b
commit e3b3657e6e
3 changed files with 23 additions and 7 deletions

View file

@ -3,16 +3,17 @@
import * as React from 'react'; import * as React from 'react';
import {Dimensions, FlatList, Image, Platform, StyleSheet, View} from 'react-native'; import {Dimensions, FlatList, Image, Platform, StyleSheet, View} from 'react-native';
import i18n from "i18n-js"; import i18n from "i18n-js";
import * as WebBrowser from 'expo-web-browser'; import {openBrowser} from "../utils/WebBrowser";
import SidebarDivider from "./SidebarDivider"; import SidebarDivider from "./SidebarDivider";
import SidebarItem from "./SidebarItem"; import SidebarItem from "./SidebarItem";
import {TouchableRipple} from "react-native-paper"; import {TouchableRipple, withTheme} from "react-native-paper";
const deviceWidth = Dimensions.get("window").width; const deviceWidth = Dimensions.get("window").width;
type Props = { type Props = {
navigation: Object, navigation: Object,
state: Object, state: Object,
theme: Object,
}; };
type State = { type State = {
@ -22,7 +23,7 @@ type State = {
/** /**
* Component used to render the drawer menu content * Component used to render the drawer menu content
*/ */
export default class SideBar extends React.PureComponent<Props, State> { class SideBar extends React.PureComponent<Props, State> {
dataSet: Array<Object>; dataSet: Array<Object>;
@ -31,6 +32,7 @@ export default class SideBar extends React.PureComponent<Props, State> {
}; };
getRenderItem: Function; getRenderItem: Function;
colors: Object;
/** /**
* Generate the dataset * Generate the dataset
@ -126,6 +128,7 @@ export default class SideBar extends React.PureComponent<Props, State> {
}, },
]; ];
this.getRenderItem = this.getRenderItem.bind(this); this.getRenderItem = this.getRenderItem.bind(this);
this.colors = props.theme.colors;
} }
/** /**
@ -138,7 +141,7 @@ export default class SideBar extends React.PureComponent<Props, State> {
if (item.link === undefined) if (item.link === undefined)
this.props.navigation.navigate(item.route); this.props.navigation.navigate(item.route);
else else
WebBrowser.openBrowserAsync(item.link); openBrowser(item.link, this.colors.primary);
} }
/** /**
@ -218,3 +221,5 @@ const styles = StyleSheet.create({
marginTop: Platform.OS === "android" ? -3 : undefined marginTop: Platform.OS === "android" ? -3 : undefined
} }
}); });
export default withTheme(SideBar);

View file

@ -4,13 +4,13 @@ import * as React from 'react';
import {View} from 'react-native'; import {View} from 'react-native';
import i18n from "i18n-js"; import i18n from "i18n-js";
import DashboardItem from "../components/EventDashboardItem"; import DashboardItem from "../components/EventDashboardItem";
import * as WebBrowser from 'expo-web-browser';
import WebSectionList from "../components/WebSectionList"; import WebSectionList from "../components/WebSectionList";
import {Text, withTheme} from 'react-native-paper'; import {Text, withTheme} from 'react-native-paper';
import FeedItem from "../components/FeedItem"; import FeedItem from "../components/FeedItem";
import SquareDashboardItem from "../components/SquareDashboardItem"; import SquareDashboardItem from "../components/SquareDashboardItem";
import PreviewEventDashboardItem from "../components/PreviewEventDashboardItem"; import PreviewEventDashboardItem from "../components/PreviewEventDashboardItem";
import {stringToDate} from "../utils/Planning"; import {stringToDate} from "../utils/Planning";
import {openBrowser} from "../utils/WebBrowser";
// import DATA from "../dashboard_data.json"; // import DATA from "../dashboard_data.json";
@ -70,7 +70,7 @@ class HomeScreen extends React.Component<Props> {
} }
onTutorInsaClick() { onTutorInsaClick() {
WebBrowser.openBrowserAsync("https://www.etud.insa-toulouse.fr/~tutorinsa/"); openBrowser("https://www.etud.insa-toulouse.fr/~tutorinsa/", this.colors.primary);
} }
onProximoClick() { onProximoClick() {
@ -402,7 +402,7 @@ class HomeScreen extends React.Component<Props> {
} }
openLink(link: string) { openLink(link: string) {
WebBrowser.openBrowserAsync(link); openBrowser(link, this.colors.primary);
} }
/** /**

11
utils/WebBrowser.js Normal file
View file

@ -0,0 +1,11 @@
// @flow
import * as React from 'react';
import * as WebBrowser from 'expo-web-browser';
export function openBrowser(url: string, color: string) {
WebBrowser.openBrowserAsync(url, {
toolbarColor: color,
enableBarCollapsing: true,
});
}