Skip to content

Commit 87c2763

Browse files
committed
docs: dark mode docs
1 parent 57be56a commit 87c2763

6 files changed

Lines changed: 84 additions & 2 deletions

File tree

docs/docs/api/register-widget-task-handler.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export async function widgetTaskHandler(props: WidgetTaskHandlerProps) {
2828
switch (props.widgetAction) {
2929
case 'WIDGET_ADDED':
3030
props.renderWidget(<Widget />);
31+
// or
32+
// props.renderWidget({
33+
// light: <Widget theme="light" />,
34+
// dark: <Widget theme="dark" />,
35+
// });
3136
break;
3237

3338
case 'WIDGET_UPDATE':

docs/docs/api/request-widget-update-by-id.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export function CounterScreen() {
3333
widgetName: 'Counter',
3434
widgetId: 1,
3535
renderWidget: () => <CounterWidget count={count} />,
36+
// or
37+
// renderWidget: () => ({
38+
// light: <CounterWidget count={count} theme="light" />,
39+
// dark: <CounterWidget count={count} theme="dark" />,
40+
// }),
3641
widgetNotFound: () => {
3742
// Called if no widget is present on the home screen
3843
},

docs/docs/api/request-widget-update.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export function CounterScreen() {
3434
requestWidgetUpdate({
3535
widgetName: 'Counter',
3636
renderWidget: () => <CounterWidget count={count} />,
37+
// or
38+
// renderWidget: () => ({
39+
// light: <CounterWidget count={count} theme="light" />,
40+
// dark: <CounterWidget count={count} theme="dark" />,
41+
// }),
3742
widgetNotFound: () => {
3843
// Called if no widget is present on the home screen
3944
}

docs/docs/tutorial/congratulations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 8
2+
sidebar_position: 9
33
---
44

55
# Congratulations!
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
sidebar_position: 7
3+
---
4+
5+
# Dark Mode widget (Optional)
6+
7+
This library supports using different colors for the widget when the system is in dark mode.
8+
It lets you provide separate widget UIs for light and dark system themes so your widget looks correct in both modes.
9+
10+
## How it works
11+
12+
When updating or rendering a widget you provide an object with `light` and/or `dark` React elements. The host system will choose the appropriate one based on the current theme. If only `light` is provided, it will be used for both modes as a fallback.
13+
14+
## registerWidgetTaskHandler
15+
16+
In a widget task handler call `props.renderWidget` and pass `light` and `dark` render trees.
17+
18+
```tsx title="widget-task-handler.tsx"
19+
import React from 'react';
20+
import { WidgetTaskHandlerProps } from 'react-native-android-widget';
21+
import { Widget } from '../../widgets/Widget';
22+
23+
export async function widgetTaskHandler(props: WidgetTaskHandlerProps) {
24+
switch (props.widgetAction) {
25+
case 'WIDGET_ADDED':
26+
case 'WIDGET_UPDATED':
27+
// props.renderWidget(<Widget />);
28+
props.renderWidget({
29+
light: <Widget theme="light" />,
30+
dark: <Widget theme="dark" />,
31+
});
32+
break;
33+
// handle other actions
34+
}
35+
}
36+
```
37+
38+
Provide both variants when colors or images need swapping for readability.
39+
40+
## requestWidgetUpdate
41+
42+
You can also request updates from anywhere in your app. The `renderWidget` callback should return the same `light`/`dark` object.
43+
44+
```tsx title="SomeComponent.tsx"
45+
import React from 'react';
46+
import { requestWidgetUpdate } from 'react-native-android-widget';
47+
import { Widget } from '../widgets/Widget';
48+
49+
function onSomeEvent() {
50+
requestWidgetUpdate({
51+
widgetName: 'Counter',
52+
renderWidget: () => ({
53+
light: <Widget theme="light" />,
54+
dark: <Widget theme="dark" />,
55+
}),
56+
});
57+
}
58+
```
59+
60+
## Limitations
61+
62+
The light and dark variants must match in structure and interactivity — they should expose the same buttons, lists, and touch targets in the same positions. Only visual styling (colors, images, icons) should differ.
63+
64+
- Structure: Keep layouts and element placement identical between variants so touch targets and spacing stay consistent.
65+
- Images and assets: If you swap images between themes, ensure they use the same intrinsic size and aspect ratio so the layout and touch regions remain unchanged.
66+
- Click handling: The native host uses the light variant for wiring click actions; the dark variant is used only for visual appearance. Make sure interactive elements in the dark variant mirror the light variant so interactions behave correctly.
67+
- Fallback: If you omit the `dark` render tree, the `light` variant will be shown in dark mode as a fallback.

docs/docs/tutorial/try-it-our.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 7
2+
sidebar_position: 8
33
---
44

55
# Try it out

0 commit comments

Comments
 (0)