forked from vergnet/application-amicale
Improved web browser handling
This commit is contained in:
parent
5bf1e7586b
commit
e3b3657e6e
3 changed files with 23 additions and 7 deletions
|
@ -3,16 +3,17 @@
|
|||
import * as React from 'react';
|
||||
import {Dimensions, FlatList, Image, Platform, StyleSheet, View} from 'react-native';
|
||||
import i18n from "i18n-js";
|
||||
import * as WebBrowser from 'expo-web-browser';
|
||||
import {openBrowser} from "../utils/WebBrowser";
|
||||
import SidebarDivider from "./SidebarDivider";
|
||||
import SidebarItem from "./SidebarItem";
|
||||
import {TouchableRipple} from "react-native-paper";
|
||||
import {TouchableRipple, withTheme} from "react-native-paper";
|
||||
|
||||
const deviceWidth = Dimensions.get("window").width;
|
||||
|
||||
type Props = {
|
||||
navigation: Object,
|
||||
state: Object,
|
||||
theme: Object,
|
||||
};
|
||||
|
||||
type State = {
|
||||
|
@ -22,7 +23,7 @@ type State = {
|
|||
/**
|
||||
* 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>;
|
||||
|
||||
|
@ -31,6 +32,7 @@ export default class SideBar extends React.PureComponent<Props, State> {
|
|||
};
|
||||
|
||||
getRenderItem: Function;
|
||||
colors: Object;
|
||||
|
||||
/**
|
||||
* Generate the dataset
|
||||
|
@ -126,6 +128,7 @@ export default class SideBar extends React.PureComponent<Props, State> {
|
|||
},
|
||||
];
|
||||
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)
|
||||
this.props.navigation.navigate(item.route);
|
||||
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
|
||||
}
|
||||
});
|
||||
|
||||
export default withTheme(SideBar);
|
||||
|
|
|
@ -4,13 +4,13 @@ import * as React from 'react';
|
|||
import {View} from 'react-native';
|
||||
import i18n from "i18n-js";
|
||||
import DashboardItem from "../components/EventDashboardItem";
|
||||
import * as WebBrowser from 'expo-web-browser';
|
||||
import WebSectionList from "../components/WebSectionList";
|
||||
import {Text, withTheme} from 'react-native-paper';
|
||||
import FeedItem from "../components/FeedItem";
|
||||
import SquareDashboardItem from "../components/SquareDashboardItem";
|
||||
import PreviewEventDashboardItem from "../components/PreviewEventDashboardItem";
|
||||
import {stringToDate} from "../utils/Planning";
|
||||
import {openBrowser} from "../utils/WebBrowser";
|
||||
// import DATA from "../dashboard_data.json";
|
||||
|
||||
|
||||
|
@ -70,7 +70,7 @@ class HomeScreen extends React.Component<Props> {
|
|||
}
|
||||
|
||||
onTutorInsaClick() {
|
||||
WebBrowser.openBrowserAsync("https://www.etud.insa-toulouse.fr/~tutorinsa/");
|
||||
openBrowser("https://www.etud.insa-toulouse.fr/~tutorinsa/", this.colors.primary);
|
||||
}
|
||||
|
||||
onProximoClick() {
|
||||
|
@ -402,7 +402,7 @@ class HomeScreen extends React.Component<Props> {
|
|||
}
|
||||
|
||||
openLink(link: string) {
|
||||
WebBrowser.openBrowserAsync(link);
|
||||
openBrowser(link, this.colors.primary);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
11
utils/WebBrowser.js
Normal file
11
utils/WebBrowser.js
Normal 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,
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue