Skip to content

Commit 8da8fd6

Browse files
docs(mkdocs): cover IS_WEB in the platform-specific code FAQ (#85)
Refs: #59 Co-authored-by: Owen Carey <[email protected]>
1 parent ac14534 commit 8da8fd6

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎docs/meta/faq.md‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,27 @@ with the native UI through a versioned bridge.
2020

2121
Yes. Two patterns:
2222

23-
- **Branch on `IS_ANDROID` / `IS_IOS`** for small differences inside
24-
a shared component:
23+
- **Branch on `IS_ANDROID` / `IS_IOS` / `IS_WEB`** for small
24+
differences inside a shared component:
2525

2626
```python
27-
from pythonnative.utils import IS_ANDROID, IS_IOS
27+
from pythonnative.utils import IS_ANDROID, IS_IOS, IS_WEB
2828

2929
if IS_ANDROID:
3030
...
3131
elif IS_IOS:
3232
...
33+
elif IS_WEB:
34+
...
3335
```
3436

37+
`pn preview` and `pn start` set `PN_PLATFORM=web`, so `IS_WEB` is
38+
`True` in the browser preview; see the
39+
[Browser preview guide](../guides/browser-preview.md).
40+
For a declarative alternative, use
41+
[`Platform.select`][pythonnative.platform.Platform.select] with the
42+
`"web"` key.
43+
3544
- **Per-platform native modules** for larger pieces (a custom widget,
3645
a device API). Implement once per platform behind a single Python
3746
facade. See [Native modules guide](../guides/native-modules.md).

0 commit comments

Comments
 (0)