Skip to content

Commit 4867d63

Browse files
authored
Merge pull request #240 from GeekyAnts/staging
Updating color-mode docs persisting colorMode example
2 parents aae0811 + e1fd279 commit 4867d63

File tree

4 files changed

+123
-11
lines changed

4 files changed

+123
-11
lines changed

docs/3.1.x/color-mode.md

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,27 @@ function App() {
117117

118118
You can persist the color mode in you app by defining you color mode manager of type `StorageManager` and passing it to the NativeBaseProvider. This will retain the color mode even when the app is refreshed.
119119

120+
- For Native
121+
120122
```jsx
121-
import React from 'react';
122-
import { NativeBaseProvider, StorageManager, ColorMode } from 'native-base';
123-
import AsyncStorage from '@react-native-async-storage/async-storage';
123+
import React from "react";
124+
import { NativeBaseProvider, StorageManager, ColorMode } from "native-base";
125+
import AsyncStorage from "@react-native-async-storage/async-storage";
124126

125127
// Define the colorModeManager,
126128
// here we are using react-native-async-storage (https://react-native-async-storage.github.io/async-storage/)
127129
const colorModeManager: StorageManager = {
128130
get: async () => {
129131
try {
130-
let val = await AsyncStorage.getItem('@color-mode');
131-
return val === 'dark' ? 'dark' : 'light';
132+
let val = await AsyncStorage.getItem("@color-mode");
133+
return val === "dark" ? "dark" : "light";
132134
} catch (e) {
133-
return 'light';
135+
return "light";
134136
}
135137
},
136138
set: async (value: ColorMode) => {
137139
try {
138-
await AsyncStorage.setItem('@color-mode', value);
140+
await AsyncStorage.setItem("@color-mode", value);
139141
} catch (e) {
140142
console.log(e);
141143
}
@@ -145,7 +147,33 @@ export default function () {
145147
return (
146148
// pass it to NativeBaseProvider
147149
<NativeBaseProvider colorModeManager={colorModeManager}>
148-
// Your components
150+
// Your components
151+
</NativeBaseProvider>
152+
);
153+
}
154+
```
155+
156+
- For web
157+
158+
```jsx
159+
import React from "react";
160+
import { ColorMode, NativeBaseProvider, StorageManager } from "native-base";
161+
const colorModeManager: StorageManager = {
162+
get: async () => {
163+
let val = localStorage.getItem("@color-mode");
164+
return val === "dark" ? "dark" : "light";
165+
},
166+
set: async (value: ColorMode) => {
167+
let strValue = value ? value.toString() : "";
168+
localStorage.setItem("@color-mode", strValue);
169+
}
170+
};
171+
172+
export default function () {
173+
return (
174+
// pass it to NativeBaseProvider
175+
<NativeBaseProvider colorModeManager={colorModeManager}>
176+
// Your components
149177
</NativeBaseProvider>
150178
);
151179
}

docs/3.2.x/color-mode.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ function App() {
9696

9797
You can persist the color mode in you app by defining you color mode manager of type `StorageManager` and passing it to the NativeBaseProvider. This will retain the color mode even when the app is refreshed.
9898

99+
- For Native
100+
99101
```jsx
100102
import React from "react";
101103
import { NativeBaseProvider, StorageManager, ColorMode } from "native-base";
@@ -124,7 +126,33 @@ export default function () {
124126
return (
125127
// pass it to NativeBaseProvider
126128
<NativeBaseProvider colorModeManager={colorModeManager}>
127-
// Your components
129+
// Your components
130+
</NativeBaseProvider>
131+
);
132+
}
133+
```
134+
135+
- For web
136+
137+
```jsx
138+
import React from "react";
139+
import { ColorMode, NativeBaseProvider, StorageManager } from "native-base";
140+
const colorModeManager: StorageManager = {
141+
get: async () => {
142+
let val = localStorage.getItem("@color-mode");
143+
return val === "dark" ? "dark" : "light";
144+
},
145+
set: async (value: ColorMode) => {
146+
let strValue = value ? value.toString() : "";
147+
localStorage.setItem("@color-mode", strValue);
148+
}
149+
};
150+
151+
export default function () {
152+
return (
153+
// pass it to NativeBaseProvider
154+
<NativeBaseProvider colorModeManager={colorModeManager}>
155+
// Your components
128156
</NativeBaseProvider>
129157
);
130158
}

docs/3.3.x/color-mode.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ function App() {
9696

9797
You can persist the color mode in you app by defining you color mode manager of type `StorageManager` and passing it to the NativeBaseProvider. This will retain the color mode even when the app is refreshed.
9898

99+
- For Native
100+
99101
```jsx
100102
import React from "react";
101103
import { NativeBaseProvider, StorageManager, ColorMode } from "native-base";
@@ -124,7 +126,33 @@ export default function () {
124126
return (
125127
// pass it to NativeBaseProvider
126128
<NativeBaseProvider colorModeManager={colorModeManager}>
127-
// Your components
129+
// Your components
130+
</NativeBaseProvider>
131+
);
132+
}
133+
```
134+
135+
- For web
136+
137+
```jsx
138+
import React from "react";
139+
import { ColorMode, NativeBaseProvider, StorageManager } from "native-base";
140+
const colorModeManager: StorageManager = {
141+
get: async () => {
142+
let val = localStorage.getItem("@color-mode");
143+
return val === "dark" ? "dark" : "light";
144+
},
145+
set: async (value: ColorMode) => {
146+
let strValue = value ? value.toString() : "";
147+
localStorage.setItem("@color-mode", strValue);
148+
}
149+
};
150+
151+
export default function () {
152+
return (
153+
// pass it to NativeBaseProvider
154+
<NativeBaseProvider colorModeManager={colorModeManager}>
155+
// Your components
128156
</NativeBaseProvider>
129157
);
130158
}

docs/next/color-mode.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ function App() {
9696

9797
You can persist the color mode in you app by defining you color mode manager of type `StorageManager` and passing it to the NativeBaseProvider. This will retain the color mode even when the app is refreshed.
9898

99+
- For Native
100+
99101
```jsx
100102
import React from "react";
101103
import { NativeBaseProvider, StorageManager, ColorMode } from "native-base";
@@ -124,7 +126,33 @@ export default function () {
124126
return (
125127
// pass it to NativeBaseProvider
126128
<NativeBaseProvider colorModeManager={colorModeManager}>
127-
// Your components
129+
// Your components
130+
</NativeBaseProvider>
131+
);
132+
}
133+
```
134+
135+
- For web
136+
137+
```jsx
138+
import React from "react";
139+
import { ColorMode, NativeBaseProvider, StorageManager } from "native-base";
140+
const colorModeManager: StorageManager = {
141+
get: async () => {
142+
let val = localStorage.getItem("@color-mode");
143+
return val === "dark" ? "dark" : "light";
144+
},
145+
set: async (value: ColorMode) => {
146+
let strValue = value ? value.toString() : "";
147+
localStorage.setItem("@color-mode", strValue);
148+
}
149+
};
150+
151+
export default function () {
152+
return (
153+
// pass it to NativeBaseProvider
154+
<NativeBaseProvider colorModeManager={colorModeManager}>
155+
// Your components
128156
</NativeBaseProvider>
129157
);
130158
}

0 commit comments

Comments
 (0)