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

feat!: add asset pipeline, fonts, icons, svg, and effects by owenthcarey · Pull Request #103 · pythonnative/pythonnative · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .css  (1) .js  (3) .json  (1) .kt  (16) .md  (13) .pbxproj  (1) .png  (4) .py  (40) .sh  (1) .svg  (1) .swift  (15) .toml  (1) .ttf  (1) .txt  (2) .yaml  (14) .yml  (2) dotfile  (1) All 17 file types selected
Only manifest files
Deleted files 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
32 changes: 18 additions & 14 deletions .github/workflows/e2e.yml
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 @@ -26,19 +26,19 @@ jobs:
needs: coverage
runs-on: ubuntu-latest
timeout-minutes: 30
# GitHub-hosted Android emulators grow unstable after ~15 minutes of
# sustained Maestro driving and start reporting "device offline" /
# "device not found" mid-run (the emulator VM, not the app, dies).
# The full suite reliably crosses that threshold around the ~35th
# flow. Sharding the run into a few balanced groups, each on its
# own freshly booted emulator, keeps every session well under the
# GitHub-hosted Android emulators grow unstable after roughly ten
# minutes of sustained Maestro driving and start reporting "device
# offline" / "device not found" mid-run (the emulator VM, not the
# app, dies). Sharding the run into a few balanced groups, each on
# its own freshly booted emulator, keeps every session under the
# limit, and parallelizes the Android pass as a bonus. Groups are
# sized so none exceeds ~15 flows; ``components`` (28 flows after
# the gesture/animated additions) crossed the ceiling at ~flow 26,
# so it runs as two halves, and ``hooks`` (22 flows after the async
# hook additions) now takes ~10 minutes of driving on its own, so
# it gets a dedicated emulator. ``fail-fast: false`` so one shard's
# failure still lets the others report.
# sized so none exceeds ~12 heavy flows: ``components`` (35 flows
# after the graphics additions) dropped offline at ~11.5 minutes
# when split in two, so it runs as three parts; ``hooks`` (23 quick
# flows, ~10 minutes of driving) gets a dedicated emulator; the
# remaining categories are grouped to similar totals.
# ``fail-fast: false`` so one shard's failure still lets the others
# report.
strategy:
fail-fast: false
matrix:
Expand All @@ -47,12 +47,14 @@ jobs:
suites: components-a
- name: components-b
suites: components-b
- name: components-c
suites: components-c
- name: hooks
suites: hooks
- name: nav-gestures-layout-styling
suites: navigation gestures layout styling
- name: anim-misc
suites: animations misc
suites: animations assets misc
- name: inbox
suites: inbox

Expand Down Expand Up @@ -162,12 +164,14 @@ jobs:
suites: components-a
- name: components-b
suites: components-b
- name: components-c
suites: components-c
- name: hooks
suites: hooks
- name: nav-gestures-layout-styling
suites: navigation gestures layout styling
- name: anim-misc
suites: animations misc
suites: animations assets misc
- name: inbox
suites: inbox

Expand Down
8 changes: 8 additions & 0 deletions AGENTS.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
@@ -1,3 +1,11 @@
# AGENTS.md

Follow Chicago Manual of Style (CMOS) grammar in the documentation, but use straight apostrophes and quotation marks, avoid em dashes, and use contractions where appropriate.

## RFCs

Major changes are designed in `rfcs/` before they're implemented. Read `rfcs/README.md` for the rules, and read the accepted RFCs before proposing a change that overlaps one of them. In short:

- Write an RFC (copy `rfcs/0000-template.md`) before adding or removing public API, changing the Python-to-native wire contract, changing a project convention apps depend on, or touching Python, Swift, Kotlin, and the browser preview at once.
- Keep the RFC honest: update it as the implementation changes, list removals explicitly, and land it with status `Implemented` in the same pull request as the code when the plan was agreed on informally.
- Bug fixes, behavior-preserving refactors, and single-layer additions don't need one.
1 change: 1 addition & 0 deletions CONTRIBUTING.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 @@ -88,6 +88,7 @@ Unsolicited pull requests for issues that are already assigned or already have a
- Prefer explicit, descriptive names; keep platform abstractions clean.
- Python never imports platform code. Everything that touches `UIView` or `android.view.View` lives in Swift (`PythonNativeKit`) or Kotlin (the `pythonnative` Gradle module) and is reached through `pythonnative.bridge`; see `docs/concepts/bridge.md` for the protocol. Bump `PROTOCOL_VERSION` on both sides when the wire format changes.
- Add/extend tests under `tests/` for new behavior. Native changes get XCTest / JUnit coverage next to the code they touch.
- Design large changes in an RFC first. Anything that adds or removes public API, changes the Python-to-native wire contract, changes a convention apps depend on, or spans Python, Swift, Kotlin, and the browser preview gets a document under `rfcs/` (see [`rfcs/README.md`](https://github.com/pythonnative/pythonnative/blob/main/rfcs/README.md)). The RFC lands with the implementation and records what shipped, including removals.
- Commit source, reviewed generated contracts, dependency locks, and vendored dependencies as described in [Generated source and vendored dependencies](#generated-source-and-vendored-dependencies). Don't commit local build outputs or caches.
- Docstrings: Google style throughout. Ruff is configured with the Google
convention (`pydocstyle.convention = "google"`) and enforces the `D` rule
Expand Down
1 change: 1 addition & 0 deletions README.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 @@ -36,6 +36,7 @@ PythonNative is a cross-platform toolkit for building native Android and iOS app
- **Incremental reconciliation:** State changes update affected component subtrees. Versioned bridge commits validate operations and acknowledge revisions; events and controlled text inputs carry identities that prevent stale updates.
- **Native lists and navigation:** UIKit collection views and Android recycler views recycle cells for fixed or variable row sizes, grids, sections, and horizontal lists. Native navigation containers present logical screen roots while providers and component state remain in the shared Python tree.
- **Animation and gestures:** Serialized animation graphs support timing, springs, decay, arithmetic, interpolation, and native scroll and gesture bindings. Swift and Kotlin recognize mobile gestures and update supported animation bindings without Python work on every frame.
- **Assets and graphics:** Drop images, fonts, and SVGs under `app/assets/` and reference them by path. Density variants, bundled fonts, a vector `Icon` set, `Svg` drawing, gradients, and blur render natively on both platforms and in the browser preview.
- **Device APIs:** Python facades expose camera, location, notifications, storage, permissions, and other native services. Test permissions and platform behavior on your deployment targets.
- **Native extension SDK:** Python dataclasses and protocols define contracts; `pn codegen` generates props and module adapters for Swift and Kotlin. Plugins package native sources and resources, and builds verify matching contracts at startup.
- **Development tools:** `pn start` serves the browser preview and connected mobile dev clients. Fast Refresh preserves compatible component state, while diagnostics report errors and invalid hook usage. Changes to native inputs trigger a rebuild.
Expand Down
40 changes: 40 additions & 0 deletions docs/api/assets.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
@@ -0,0 +1,40 @@
# Assets

Files under `app/assets/` are bundled into the iOS app, the Android APK,
and the browser preview, and are addressed from Python by relative path:

```python
import pythonnative as pn

logo = pn.asset("images/logo.png") # Asset("images/logo.png")
pn.Image(source=logo, style=pn.style(width=120, height=40))
config = pn.asset("data/config.json").read_text()
```

The [Assets guide](../guides/assets.md) covers density variants, fonts,
icons, and how the folder is bundled and synced.

::: pythonnative.assets
options:
show_root_heading: false
show_root_toc_entry: false
members_order: source
filters: ["!^_"]

## Fonts

Bundled `.ttf` and `.otf` files are parsed at build time so `font_family`
can refer to them by family name.

::: pythonnative.assets.fonts
options:
show_root_heading: false
show_root_toc_entry: false
members_order: source
filters: ["!^_"]

## Next steps

- Measure and prefetch images with [`Images`](images.md).
- Draw bundled vectors with [`Svg`][pythonnative.components.Svg] and
[`Icon`][pythonnative.Icon]: see [Graphics](graphics.md).
44 changes: 44 additions & 0 deletions docs/api/graphics.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
@@ -0,0 +1,44 @@
# Graphics

Vector drawing and visual effects: [`Icon`][pythonnative.Icon] for the
bundled Lucide icon set, [`Svg`][pythonnative.components.Svg] with the shape
classes in `pythonnative.svg` (below), and the
[`LinearGradient`][pythonnative.components.LinearGradient] and
[`BlurView`][pythonnative.components.BlurView] containers. The component
factories themselves are documented on the [Components](components.md) page.

```python
import pythonnative as pn
from pythonnative import svg

pn.Icon("heart", color="#DC2626")

pn.Svg(
svg.Circle(cx=12, cy=12, r=10, fill="#FDE68A"),
svg.Path(d="M8 13 q4 5 8 0", stroke="#B45309", stroke_width=2, fill="none"),
style=pn.style(width=48, height=48),
)

pn.LinearGradient(pn.Text("Hi"), colors=["#6366F1", "#EC4899"], style=pn.style(padding=16))
```

See the [Assets guide](../guides/assets.md) for the drawing model and
platform notes.

## Icons

::: pythonnative.icons
options:
show_root_heading: false
show_root_toc_entry: false
members_order: source
filters: ["!^_"]

## SVG shapes and parsing

::: pythonnative.svg
options:
show_root_heading: false
show_root_toc_entry: false
members_order: source
filters: ["!^_"]
45 changes: 40 additions & 5 deletions docs/api/images.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
@@ -1,8 +1,43 @@
# Images

`Image` loads and decodes images with the platform's native image loader. Each
platform caches responses and cancels obsolete requests when a source changes
or a component unmounts. Python doesn't download or decode image bytes.
`Image` loads and decodes images with the platform's native image loader.
Each platform caches responses and cancels obsolete requests when a source
changes or a component unmounts. Python doesn't download or decode image
bytes.

Use `Image(source=...)` for bundled resources, files, or remote images. Supply
layout constraints when an image must reserve space before its content loads.
Sources can be a bundled [`Asset`][pythonnative.Asset], an `https` URL, a
file path, or a `data:` URI. `default_source` shows a local image while a
remote one loads (and keeps it if the load fails); `blur_radius` blurs the
decoded bitmap. Supply layout constraints when an image must reserve space
before its content loads.

```python
pn.Image(
source="https://example.com/photo.jpg",
default_source=pn.asset("images/placeholder.png"),
blur_radius=4,
style=pn.style(width=200, height=120),
)
```

## Images module

[`Images`][pythonnative.Images] measures, prefetches, and clears the
cache of the same pipeline:

```python
size = await pn.Images.get_size(pn.asset("images/hero.png"))
await pn.Images.prefetch("https://example.com/photo.jpg")
pn.Images.clear_cache()
```

::: pythonnative.native_modules.images
options:
show_root_heading: false
show_root_toc_entry: false
members_order: source
filters: ["!^_"]

## Next steps

- Bundle images, fonts, and vectors: [Assets guide](../guides/assets.md).
Loading
Loading

Back | FazBrowse Home | New Git URL