|
| 1 | +from abc import ABC, abstractmethod |
1 | 2 | from .utils import IS_ANDROID |
2 | | -from .view import View |
| 3 | +from .view import ViewBase |
| 4 | + |
| 5 | +# ======================================== |
| 6 | +# Base class |
| 7 | +# ======================================== |
| 8 | + |
| 9 | + |
| 10 | +class LinearLayoutBase(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 | + |
3 | 20 |
|
4 | 21 | if IS_ANDROID: |
| 22 | + # ======================================== |
| 23 | + # Android class |
| 24 | + # ======================================== |
| 25 | + |
5 | 26 | from java import jclass |
6 | 27 |
|
7 | | - class LinearLayout(View): |
| 28 | + class LinearLayout(LinearLayoutBase, ViewBase): |
8 | 29 | def __init__(self, context) -> None: |
9 | 30 | super().__init__() |
10 | 31 | self.native_class = jclass("android.widget.LinearLayout") |
11 | 32 | self.native_instance = self.native_class(context) |
12 | 33 | self.native_instance.setOrientation(self.native_class.VERTICAL) |
13 | | - self.views = [] |
14 | 34 |
|
15 | 35 | def add_view(self, view): |
16 | 36 | self.views.append(view) |
17 | 37 | self.native_instance.addView(view.native_instance) |
18 | 38 |
|
19 | 39 | else: |
| 40 | + # ======================================== |
| 41 | + # iOS class |
| 42 | + # ======================================== |
| 43 | + |
20 | 44 | from rubicon.objc import ObjCClass |
21 | 45 |
|
22 | | - class LinearLayout(View): |
| 46 | + class LinearLayout(LinearLayoutBase, ViewBase): |
23 | 47 | def __init__(self) -> None: |
24 | 48 | super().__init__() |
25 | 49 | self.native_class = ObjCClass("UIStackView") |
26 | 50 | self.native_instance = self.native_class.alloc().initWithFrame_( |
27 | 51 | ((0, 0), (0, 0)) |
28 | 52 | ) |
29 | 53 | self.native_instance.setAxis_(0) # Set axis to vertical |
30 | | - self.views = [] |
31 | 54 |
|
32 | 55 | def add_view(self, view): |
33 | 56 | self.views.append(view) |
|
0 commit comments