| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b55edd4 commit c8c3448
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ | |||
| 14 | 14 | from .page import Page | |
| 15 | 15 | from .picker_view import PickerView | |
| 16 | 16 | from .progress_view import ProgressView | |
| 17 | + from .scroll_view import ScrollView | ||
| 17 | 18 | from .search_bar import SearchBar | |
| 18 | 19 | from .stack_view import StackView | |
| 19 | 20 | from .switch import Switch | |
@@ -39,6 +40,7 @@ | |||
| 39 | 40 | "Page", | |
| 40 | 41 | "PickerView", | |
| 41 | 42 | "ProgressView", | |
| 43 | + "ScrollView", | ||
| 42 | 44 | "SearchBar", | |
| 43 | 45 | "StackView", | |
| 44 | 46 | "Switch", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -134,8 +134,10 @@ def on_restore_instance_state(self) -> None: | |||
| 134 | 134 | ||
| 135 | 135 | def navigate_to(self, page) -> None: | |
| 136 | 136 | # intent = jclass("android.content.Intent")(self.native_instance, page.native_class) | |
| 137 | - intent = jclass("android.content.Intent")(self.native_instance, | ||
| 138 | - jclass("com.pythonnative.pythonnative.SecondActivity")) | ||
| 137 | + intent = jclass("android.content.Intent")( | ||
| 138 | + self.native_instance, | ||
| 139 | + jclass("com.pythonnative.pythonnative.SecondActivity"), | ||
| 140 | + ) | ||
| 139 | 141 | self.native_instance.startActivity(intent) | |
| 140 | 142 | ||
| 141 | 143 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,61 @@ | |||
| 1 | + from abc import ABC, abstractmethod | ||
| 2 | + from .utils import IS_ANDROID | ||
| 3 | + from .view import ViewBase | ||
| 4 | + | ||
| 5 | + # ======================================== | ||
| 6 | + # Base class | ||
| 7 | + # ======================================== | ||
| 8 | + | ||
| 9 | + | ||
| 10 | + class ScrollViewBase(ABC): | ||
| 11 | + @abstractmethod | ||
| 12 | + def __init__(self) -> None: | ||
| 13 | + super().__init__() | ||
| 14 | + self.views = [] | ||
| 15 | + | ||
| 16 | + @abstractmethod | ||
| 17 | + def add_view(self, view) -> None: | ||
| 18 | + pass | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + if IS_ANDROID: | ||
| 22 | + # ======================================== | ||
| 23 | + # Android class | ||
| 24 | + # ======================================== | ||
| 25 | + | ||
| 26 | + from java import jclass | ||
| 27 | + | ||
| 28 | + class ScrollView(ScrollViewBase, ViewBase): | ||
| 29 | + def __init__(self, context) -> None: | ||
| 30 | + super().__init__() | ||
| 31 | + self.native_class = jclass("android.widget.ScrollView") | ||
| 32 | + self.native_instance = self.native_class(context) | ||
| 33 | + | ||
| 34 | + def add_view(self, view): | ||
| 35 | + self.views.append(view) | ||
| 36 | + # In Android, ScrollView can host only one direct child | ||
| 37 | + if len(self.views) == 1: | ||
| 38 | + self.native_instance.addView(view.native_instance) | ||
| 39 | + else: | ||
| 40 | + raise Exception("ScrollView can host only one direct child") | ||
| 41 | + | ||
| 42 | + else: | ||
| 43 | + # ======================================== | ||
| 44 | + # iOS class | ||
| 45 | + # ======================================== | ||
| 46 | + | ||
| 47 | + from rubicon.objc import ObjCClass | ||
| 48 | + | ||
| 49 | + class ScrollView(ScrollViewBase, ViewBase): | ||
| 50 | + def __init__(self) -> None: | ||
| 51 | + super().__init__() | ||
| 52 | + self.native_class = ObjCClass("UIScrollView") | ||
| 53 | + self.native_instance = self.native_class.alloc().initWithFrame_( | ||
| 54 | + ((0, 0), (0, 0)) | ||
| 55 | + ) | ||
| 56 | + | ||
| 57 | + def add_view(self, view): | ||
| 58 | + self.views.append(view) | ||
| 59 | + # Ensure view is a subview of scrollview | ||
| 60 | + if view.native_instance not in self.native_instance.subviews: | ||
| 61 | + self.native_instance.addSubview_(view.native_instance) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments