Skip to content

Latest commit

 

History

History
65 lines (41 loc) · 2.89 KB

File metadata and controls

65 lines (41 loc) · 2.89 KB

pythonnative package

Public API

Page

pythonnative.Page — base class for screens. Subclass it, implement render(), and use set_state() to trigger re-renders.

Element functions

  • pythonnative.Text, Button, Column, Row, ScrollView, TextInput, Image, Switch, ProgressBar, ActivityIndicator, WebView, Spacer
  • pythonnative.View, SafeAreaView, Modal, Slider, Pressable, FlatList

Each returns an Element descriptor. See the Component Property Reference for full signatures.

Element

pythonnative.Element — the descriptor type returned by element functions. You generally don't create these directly.

Hooks

Function component primitives:

  • pythonnative.component — decorator to create a function component
  • pythonnative.use_state(initial) — local component state
  • pythonnative.use_effect(effect, deps) — side effects
  • pythonnative.use_memo(factory, deps) — memoised values
  • pythonnative.use_callback(fn, deps) — stable function references
  • pythonnative.use_ref(initial) — mutable ref object
  • pythonnative.use_context(context) — read from context
  • pythonnative.create_context(default) — create a new context
  • pythonnative.Provider(context, value, child) — provide a context value

Styling

  • pythonnative.StyleSheet — utility for creating and composing style dicts
  • pythonnative.ThemeContext — built-in theme context (defaults to light theme)

Native API modules

  • pythonnative.native_modules.Camera — photo capture and gallery picking
  • pythonnative.native_modules.Location — GPS / location services
  • pythonnative.native_modules.FileSystem — app-scoped file I/O
  • pythonnative.native_modules.Notifications — local push notifications

Internal helpers

  • pythonnative.utils.IS_ANDROID — platform flag with robust detection for Chaquopy/Android.
  • pythonnative.utils.get_android_context() — returns the current Android Activity/Context when running on Android.
  • pythonnative.utils.set_android_context(ctx) — set by Page on Android; you generally don't call this directly.
  • pythonnative.utils.get_android_fragment_container() — returns the current Fragment container ViewGroup used for page rendering.

Reconciler

pythonnative.reconciler.Reconciler — diffs element trees and applies minimal native mutations. Supports key-based child reconciliation, function components, and context providers. Used internally by Page.

Hot reload

pythonnative.hot_reload.FileWatcher — watches a directory for file changes and triggers a callback. Used by pn run --hot-reload.

pythonnative.hot_reload.ModuleReloader — reloads changed Python modules on the device and triggers page re-rendering.

Native view registry

pythonnative.native_views.NativeViewRegistry — maps element type names to platform-specific handlers. Use set_registry() to inject a mock for testing.