forked from vergnet/application-amicale
Fixed qr code crash
This commit is contained in:
parent
8a1f0d110b
commit
6607d9206b
1 changed files with 39 additions and 11 deletions
|
@ -1,9 +1,11 @@
|
|||
// @flow
|
||||
|
||||
import {Linking} from 'expo';
|
||||
import {Linking} from 'react-native';
|
||||
|
||||
export default class URLHandler {
|
||||
|
||||
static SCHEME = "campus-insat://";
|
||||
|
||||
static CLUB_INFO_URL_PATH = "club";
|
||||
static EVENT_INFO_URL_PATH = "event";
|
||||
|
||||
|
@ -20,21 +22,47 @@ export default class URLHandler {
|
|||
|
||||
listen() {
|
||||
Linking.addEventListener('url', this.onUrl);
|
||||
Linking.parseInitialURLAsync().then(this.onInitialUrl);
|
||||
Linking.getInitialURL().then(this.onInitialUrl);
|
||||
}
|
||||
|
||||
onUrl = ({url}: Object) => {
|
||||
let data = URLHandler.getUrlData(Linking.parse(url));
|
||||
if (data !== null)
|
||||
this.onDetectURL(data);
|
||||
onUrl = ({url}: { url: string }) => {
|
||||
if (url != null) {
|
||||
let data = URLHandler.getUrlData(URLHandler.parseUrl(url));
|
||||
if (data !== null)
|
||||
this.onDetectURL(data);
|
||||
}
|
||||
};
|
||||
|
||||
onInitialUrl = ({path, queryParams}: Object) => {
|
||||
let data = URLHandler.getUrlData({path, queryParams});
|
||||
if (data !== null)
|
||||
this.onInitialURLParsed(data);
|
||||
onInitialUrl = (url: ?string) => {
|
||||
if (url != null) {
|
||||
let data = URLHandler.getUrlData(URLHandler.parseUrl(url));
|
||||
if (data !== null)
|
||||
this.onInitialURLParsed(data);
|
||||
}
|
||||
};
|
||||
|
||||
static parseUrl(url: string) {
|
||||
let params = {};
|
||||
let path = "";
|
||||
let temp = url.replace(URLHandler.SCHEME, "");
|
||||
if (temp != null) {
|
||||
let array = temp.split("?");
|
||||
if (array != null && array.length > 0) {
|
||||
path = array[0];
|
||||
}
|
||||
if (array != null && array.length > 1) {
|
||||
let tempParams = array[1].split("&");
|
||||
for (let i = 0; i < tempParams.length; i++) {
|
||||
let paramsArray = tempParams[i].split("=");
|
||||
if (paramsArray.length > 1) {
|
||||
params[paramsArray[0]] = paramsArray[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {path: path, queryParams: params};
|
||||
}
|
||||
|
||||
static getUrlData({path, queryParams}: Object) {
|
||||
let data = null;
|
||||
if (path !== null) {
|
||||
|
@ -47,7 +75,7 @@ export default class URLHandler {
|
|||
}
|
||||
|
||||
static isUrlValid(url: string) {
|
||||
return this.getUrlData(Linking.parse(url)) !== null;
|
||||
return this.getUrlData(URLHandler.parseUrl(url)) !== null;
|
||||
}
|
||||
|
||||
static isClubInformationLink(path: string) {
|
||||
|
|
Loading…
Reference in a new issue