FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

docs(mkdocs): cover IS_WEB in the platform-specific code FAQ by nigelseah24 · Pull Request #85 · pythonnative/pythonnative · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 12 additions & 3 deletions docs/meta/faq.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,27 @@ with the native UI through a versioned bridge.

Yes. Two patterns:

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

```python
from pythonnative.utils import IS_ANDROID, IS_IOS
from pythonnative.utils import IS_ANDROID, IS_IOS, IS_WEB

if IS_ANDROID:
...
elif IS_IOS:
...
elif IS_WEB:
...
```

`pn preview` and `pn start` set `PN_PLATFORM=web`, so `IS_WEB` is
`True` in the browser preview; see the
[Browser preview guide](../guides/browser-preview.md).
For a declarative alternative, use
[`Platform.select`][pythonnative.platform.Platform.select] with the
`"web"` key.

- **Per-platform native modules** for larger pieces (a custom widget,
a device API). Implement once per platform behind a single Python
facade. See [Native modules guide](../guides/native-modules.md).
Expand Down
Loading

Back | FazBrowse Home | New Git URL