forked from ibitcy/react-native-root-view-background
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackgroundManager.ios.js
More file actions
29 lines (24 loc) · 813 Bytes
/
Copy pathBackgroundManager.ios.js
File metadata and controls
29 lines (24 loc) · 813 Bytes
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
import { NativeModules } from 'react-native';
function hexToRgb(hex) {
let c;
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
c = hex.substring(1).split('');
if (c.length === 3) {
c = [c[0], c[0], c[1], c[1], c[2], c[2]];
}
c = `0x${c.join('')}`;
const red = parseFloat((c >> 16) & 255);
const green = parseFloat((c >> 8) & 255);
const blue = parseFloat(c & 255);
return [red, green, blue];
}
throw new Error('Bad Hex');
}
function setRootViewBackgroundColor(hex) {
const [r, g, b] = hexToRgb(hex);
setRootViewBackgroundColorWithRGB(r, g, b, 1);
}
function setRootViewBackgroundColorWithRGB(r, g, b, a) {
NativeModules.RNRootViewBackground.setBackground(r, g, b, a);
}
export { setRootViewBackgroundColor };