Skip to content

Commit d0068fd

Browse files
committed
refactor(native_views)!: split monolithic module into platform-specific package
1 parent a7ef3d5 commit d0068fd

File tree

10 files changed

+1696
-1406
lines changed

10 files changed

+1696
-1406
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Recommended scopes (choose the smallest, most accurate unit; prefer module/direc
103103
- `hooks` – function components and hooks (`hooks.py`)
104104
- `hot_reload` – file watcher and module reloader (`hot_reload.py`)
105105
- `native_modules` – native API modules for device capabilities (`native_modules/`)
106-
- `native_views` – platform-specific native view creation and updates (`native_views.py`)
106+
- `native_views` – platform-specific native view creation and updates (`native_views/`)
107107
- `package``src/pythonnative/__init__.py` exports and package boundary
108108
- `page` – Page component, lifecycle, and reactive state (`page.py`)
109109
- `reconciler` – virtual view tree diffing and reconciliation (`reconciler.py`)

docs/api/pythonnative.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ Function component primitives:
6464
## Native view registry
6565

6666
`pythonnative.native_views.NativeViewRegistry` — maps element type names to platform-specific handlers. Use `set_registry()` to inject a mock for testing.
67+
68+
The `native_views` package is organised into submodules:
69+
70+
- `pythonnative.native_views.base` — shared `ViewHandler` protocol and utilities (`parse_color_int`, `resolve_padding`, `LAYOUT_KEYS`)
71+
- `pythonnative.native_views.android` — Android handlers (only imported at runtime on Android via Chaquopy)
72+
- `pythonnative.native_views.ios` — iOS handlers (only imported at runtime on iOS via rubicon-objc)

docs/concepts/architecture.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ The entry point `create_page()` is called internally by native templates to boot
5656

5757
All components support layout properties inside the `style` dict: `width`, `height`, `flex`, `margin`, `min_width`, `max_width`, `min_height`, `max_height`, `align_self`. Containers (`Column`, `Row`) support `spacing`, `padding`, `alignment`, `align_items`, and `justify_content`.
5858

59+
## Native view handlers
60+
61+
Platform-specific rendering logic lives in the `native_views` package, organised into dedicated submodules:
62+
63+
- `native_views.base` — shared `ViewHandler` protocol and common utilities (colour parsing, padding resolution, layout keys)
64+
- `native_views.android` — Android handlers using Chaquopy's Java bridge (`jclass`, `dynamic_proxy`)
65+
- `native_views.ios` — iOS handlers using rubicon-objc (`ObjCClass`, `objc_method`)
66+
67+
Each handler class maps an element type name (e.g. `"Text"`, `"Button"`) to platform-native widget creation, property updates, and child management. The `NativeViewRegistry` lazily imports only the relevant platform module at runtime, so the package can be imported on any platform for testing.
68+
5969
## Comparison
6070

6171
- **Versus React Native:** RN uses JSX + a JavaScript bridge + Yoga layout. PythonNative uses Python + direct native calls + platform layout managers. No JS bridge, no serialisation overhead.

mypy.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
python_version = 3.9
2+
python_version = 3.10
33
ignore_missing_imports = True
44
warn_redundant_casts = True
55
warn_unused_ignores = True
@@ -17,3 +17,6 @@ disable_error_code = attr-defined,no-redef
1717

1818
[mypy-pythonnative.native_views]
1919
disable_error_code = misc
20+
21+
[mypy-pythonnative.native_views.*]
22+
disable_error_code = misc

0 commit comments

Comments
 (0)