-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helper.js
103 lines (86 loc) · 2.41 KB
/
Helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Alert } from 'react-native';
import { CommonActions } from '@react-navigation/native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { Colors, ImagePath, IMAGES } from './Constants';
export function setHeaderColor(navigation) {
navigation.setOptions({
headerStyle: {
backgroundColor: Colors.primaryColor,
}
})
}
//Make root
export function navigateWithRoot(control, navigation) {
navigation.dispatch(
CommonActions.reset({
index: 1,
routes: [
{ name: control },
]
})
);
}
//Remove from Async storage
export async function removefromAsync(key) {
try {
await AsyncStorage.removeItem(key)
} catch (e) {
// remove error
console.log('erorr.........', e)
}
console.log('Done.')
}
//Get from Async storage
export async function getFromAsync(key) {
try {
const value = await AsyncStorage.getItem(key)
return value
} catch (e) {
// error reading value
}
}
//Store in Async storage
export async function storeInAsync(key, value) {
try {
await AsyncStorage.setItem(key, value)
} catch (e) {
// saving error
}
}
//Validate Email
export function validateEmail(text) {
console.log(text);
let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (reg.test(text) === false) {
console.log("Email is Not Correct");
alert('Invalid Email address')
return false;
}
else {
console.log("Email is Correct");
return true;
}
}
export function isEmpty(value) {
return (value == '')
}
export function alertConfirm(title, message, action) {
Alert.alert(title, message,
[
{ text: "No", style: "cancel" },
{
text: "Yes", onPress: () => { action() }
}
],
{ cancelable: false }
)
}
export function getImagePath(item) {
return item.logo != null ? { uri: item.logo.includes('http') ? item.logo : ImagePath + item.logo } : item.thumb ? item.thumb != '' ? { uri: ImagePath + item.thumb } : IMAGES.LOGO : IMAGES.LOGO
}
export function arrayToString(array) {
return array.map((obj, index) => { return `${obj}${(index + 1) == array.length ? '' : ','} ` })
}
export function firstLetterCapital(string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}