-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.tsx
56 lines (52 loc) · 1.55 KB
/
platform.tsx
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
import { Platform } from 'react-native';
export function autoFocus(): boolean {
return Platform.select({
ios: false,
android: false,
default: false,
});
}
/**
* {@link file:///Users/asterisk/Codes/zuoyu/react-native-chat-library/node_modules/@types/react-native/index.d.ts}
* #CameraRollStatic.saveImageWithTag
*
* On Android, this is a local URI, such as "file:///sdcard/img.png".
* On iOS, the tag can be one of the following:
* local URI
* assets-library tag
* a tag not matching any of the above, which means the image data will be stored in memory (and consume memory as long as the process is alive)
*
* @param localPath local path.
*
* @returns local path
*/
export function localUrl(localPath: string): string {
return Platform.select({
ios: localPath,
android: localPath.includes('file://') ? localPath : `file://${localPath}`,
default: localPath,
});
}
export function removeFileHeader(localPath: string): string {
return Platform.select({
ios: localPath.startsWith('file://')
? localPath.replace('file://', '')
: localPath,
android: localPath,
default: localPath,
});
}
export function playUrl(localPath: string): string {
return Platform.select({
ios: localPath.startsWith('file://') ? localPath : `file://${localPath}`,
android: localPath,
default: localPath,
});
}
export function localUrlEscape(localPath: string): string {
if (localPath.startsWith('file://')) {
return localPath.replace(/#/g, '%23').replace(/ /g, '%20');
} else {
return localPath;
}
}