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
|
// @flow
|
||||||
|
|
||||||
import {Linking} from 'expo';
|
import {Linking} from 'react-native';
|
||||||
|
|
||||||
export default class URLHandler {
|
export default class URLHandler {
|
||||||
|
|
||||||
|
static SCHEME = "campus-insat://";
|
||||||
|
|
||||||
static CLUB_INFO_URL_PATH = "club";
|
static CLUB_INFO_URL_PATH = "club";
|
||||||
static EVENT_INFO_URL_PATH = "event";
|
static EVENT_INFO_URL_PATH = "event";
|
||||||
|
|
||||||
|
@ -20,21 +22,47 @@ export default class URLHandler {
|
||||||
|
|
||||||
listen() {
|
listen() {
|
||||||
Linking.addEventListener('url', this.onUrl);
|
Linking.addEventListener('url', this.onUrl);
|
||||||
Linking.parseInitialURLAsync().then(this.onInitialUrl);
|
Linking.getInitialURL().then(this.onInitialUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
onUrl = ({url}: Object) => {
|
onUrl = ({url}: { url: string }) => {
|
||||||
let data = URLHandler.getUrlData(Linking.parse(url));
|
if (url != null) {
|
||||||
if (data !== null)
|
let data = URLHandler.getUrlData(URLHandler.parseUrl(url));
|
||||||
this.onDetectURL(data);
|
if (data !== null)
|
||||||
|
this.onDetectURL(data);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onInitialUrl = ({path, queryParams}: Object) => {
|
onInitialUrl = (url: ?string) => {
|
||||||
let data = URLHandler.getUrlData({path, queryParams});
|
if (url != null) {
|
||||||
if (data !== null)
|
let data = URLHandler.getUrlData(URLHandler.parseUrl(url));
|
||||||
this.onInitialURLParsed(data);
|
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) {
|
static getUrlData({path, queryParams}: Object) {
|
||||||
let data = null;
|
let data = null;
|
||||||
if (path !== null) {
|
if (path !== null) {
|
||||||
|
@ -47,7 +75,7 @@ export default class URLHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
static isUrlValid(url: string) {
|
static isUrlValid(url: string) {
|
||||||
return this.getUrlData(Linking.parse(url)) !== null;
|
return this.getUrlData(URLHandler.parseUrl(url)) !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static isClubInformationLink(path: string) {
|
static isClubInformationLink(path: string) {
|
||||||
|
|
Loading…
Reference in a new issue