Skip to content

Commit f3a03b0

Browse files
committed
docs(mkdocs): update Getting Started, Hello World, Components, and platform guides
1 parent 4c06b67 commit f3a03b0

File tree

5 files changed

+133
-9
lines changed

5 files changed

+133
-9
lines changed

docs/concepts/components.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,23 @@ class MainPage(pn.Page):
2929
Notes:
3030
- `pn.Page` stores the Android `Activity` so components like `pn.Button()` and `pn.Label()` can construct their native counterparts.
3131
- If you construct views before the `Page` is created on Android, a runtime error will be raised because no `Context` is available.
32+
33+
## Core components (0.2.0)
34+
35+
Stabilized with contextless constructors on both platforms:
36+
37+
- `Page`
38+
- `StackView`
39+
- `Label`, `Button`
40+
- `ImageView`
41+
- `TextField`, `TextView`
42+
- `Switch`
43+
- `ProgressView`, `ActivityIndicatorView`
44+
- `WebView`
45+
46+
APIs are intentionally small and grow progressively in later releases. Properties and setters are kept consistent where supported by both platforms.
47+
48+
## Platform detection and Android context
49+
50+
- Use `pythonnative.utils.IS_ANDROID` for platform checks when needed.
51+
- On Android, `Page` records the current `Activity` so child views can acquire a `Context` implicitly. Constructing views before `Page` initialization will raise.

docs/examples/hello-world.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
11
# Hello World
22

3-
A minimal placeholder example. Replace with a real example later.
3+
Create a simple page with a label and a button.
4+
5+
```python
6+
import pythonnative as pn
7+
8+
9+
class MainPage(pn.Page):
10+
def __init__(self, native_instance):
11+
super().__init__(native_instance)
12+
13+
def on_create(self):
14+
super().on_create()
15+
stack = pn.StackView()
16+
label = pn.Label("Hello, world!")
17+
button = pn.Button("Tap me")
18+
button.set_on_click(lambda: print("Hello tapped"))
19+
stack.add_view(label)
20+
stack.add_view(button)
21+
self.set_root_view(stack)
22+
```
23+
24+
Run it:
25+
26+
```bash
27+
pn run android
28+
# or
29+
pn run ios
30+
```

docs/getting-started.md

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,63 @@ pip install pythonnative
55
pn --help
66
```
77

8-
- Install: `pip install pythonnative`
9-
- Create a project: `pn init my_app`
10-
- Scaffolds `app/`, `pythonnative.json`, `requirements.txt`, `.gitignore`
11-
- Run: `pn run android` or `pn run ios`
12-
- Uses bundled templates; copies your `app/` into the platform project
13-
- On Android, `pn.Page` provides the Activity context so components can be created without passing a context
14-
- Clean: `pn clean`
15-
- Removes the `build/` directory safely
8+
## Create a project
9+
10+
```bash
11+
pn init MyApp
12+
```
13+
14+
This scaffolds:
15+
16+
- `app/` with a minimal `main_page.py`
17+
- `pythonnative.json` project config
18+
- `requirements.txt`
19+
- `.gitignore`
20+
21+
A minimal `app/main_page.py` looks like:
22+
23+
```python
24+
import pythonnative as pn
25+
26+
27+
class MainPage(pn.Page):
28+
def __init__(self, native_instance):
29+
super().__init__(native_instance)
30+
31+
def on_create(self):
32+
super().on_create()
33+
stack = pn.StackView()
34+
stack.add_view(pn.Label("Hello from PythonNative!"))
35+
button = pn.Button("Tap me")
36+
button.set_on_click(lambda: print("Button clicked"))
37+
stack.add_view(button)
38+
self.set_root_view(stack)
39+
```
40+
41+
## Run on a platform
42+
43+
```bash
44+
pn run android
45+
# or
46+
pn run ios
47+
```
48+
49+
- Uses bundled templates (no network required for scaffolding)
50+
- Copies your `app/` into the generated project
51+
52+
If you just want to scaffold the platform project without building, use:
53+
54+
```bash
55+
pn run android --prepare-only
56+
pn run ios --prepare-only
57+
```
58+
59+
This stages files under `build/` so you can open them in Android Studio or Xcode.
60+
61+
## Clean
62+
63+
Remove the build artifacts safely:
64+
65+
```bash
66+
pn clean
67+
```

docs/guides/android.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,16 @@ pn run android --prepare-only
2121
```
2222

2323
This will stage files under `build/android/android_template` so you can open it in Android Studio if you prefer.
24+
25+
## Clean
26+
27+
Remove the build directory safely:
28+
29+
```bash
30+
pn clean
31+
```
32+
33+
## Troubleshooting
34+
35+
- If `gradlew` fails due to JDK path on macOS, ensure `JAVA_HOME` is set (the CLI attempts to detect Homebrew `openjdk@17`).
36+
- Ensure an Android emulator or device is available for `installDebug`.

docs/guides/ios.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ pn run ios --prepare-only
2121
```
2222

2323
You can then open `build/ios/ios_template/ios_template.xcodeproj` in Xcode.
24+
25+
## Clean
26+
27+
Remove the build directory safely:
28+
29+
```bash
30+
pn clean
31+
```
32+
33+
## Notes
34+
35+
- Building and running for Simulator via the CLI is best-effort. Opening the generated project in Xcode is recommended for iterative development.

0 commit comments

Comments
 (0)