@@ -12,7 +12,26 @@ class PlatformNotDetectedError(Exception):
1212if system == "iOS" :
1313 from rubicon .objc import ObjCClass
1414
15- # Map native iOS classes to PythonNative classes
15+ class Screen :
16+ native_class = ObjCClass ("UIViewController" )
17+
18+ def __init__ (self ):
19+ self .native_instance = self .native_class .alloc ().init ()
20+ self .layout = None
21+
22+ def add_view (self , view ):
23+ if self .layout is None :
24+ raise ValueError ("You must set a layout before adding views." )
25+ self .layout .add_view (view )
26+
27+ def set_layout (self , layout ):
28+ self .layout = layout
29+ self .native_instance .view ().addSubview_ (layout .native_instance )
30+
31+ def show (self ):
32+ # This method should contain code to present the ViewController
33+ pass
34+
1635 class Button :
1736 native_class = ObjCClass ("UIButton" )
1837
@@ -26,7 +45,6 @@ def set_title(self, title: str) -> None:
2645 def get_title (self ) -> str :
2746 return self .native_instance .titleForState_ (0 )
2847
29-
3048 class Label :
3149 native_class = ObjCClass ("UILabel" )
3250
@@ -40,25 +58,43 @@ def set_text(self, text: str) -> None:
4058 def get_text (self ) -> str :
4159 return self .native_instance .text ()
4260
43-
4461 class LinearLayout :
4562 native_class = ObjCClass ("UIStackView" )
4663
4764 def __init__ (self ) -> None :
4865 self .native_instance = self .native_class .alloc ().initWithFrame_ (
49- ((0 , 0 ), (0 , 0 )))
66+ ((0 , 0 ), (0 , 0 ))
67+ )
5068 self .native_instance .setAxis_ (0 ) # Set axis to vertical
5169 self .views = []
5270
5371 def add_view (self , view ):
5472 self .views .append (view )
5573 self .native_instance .addArrangedSubview_ (view .native_instance )
5674
57-
5875elif system == "Android" :
5976 from java import jclass
6077
61- # Map native Android classes to PythonNative classes
78+ class Screen :
79+ native_class = jclass ("android.app.Activity" )
80+
81+ def __init__ (self ):
82+ self .native_instance = self .native_class ()
83+ self .layout = None
84+
85+ def add_view (self , view ):
86+ if self .layout is None :
87+ raise ValueError ("You must set a layout before adding views." )
88+ self .layout .add_view (view )
89+
90+ def set_layout (self , layout ):
91+ self .layout = layout
92+ self .native_instance .setContentView (layout .native_instance )
93+
94+ def show (self ):
95+ # This method should contain code to start the Activity
96+ pass
97+
6298 class Button :
6399 native_class = jclass ("android.widget.Button" )
64100
@@ -72,7 +108,6 @@ def set_title(self, title: str) -> None:
72108 def get_title (self ) -> str :
73109 return self .native_instance .getText ().toString ()
74110
75-
76111 class Label :
77112 native_class = jclass ("android.widget.TextView" )
78113
@@ -86,20 +121,17 @@ def set_text(self, text: str) -> None:
86121 def get_text (self ) -> str :
87122 return self .native_instance .getText ().toString ()
88123
89-
90124 class LinearLayout :
91125 native_class = jclass ("android.widget.LinearLayout" )
92126
93127 def __init__ (self ) -> None :
94128 self .native_instance = self .native_class ()
95- self .native_instance .setOrientation (
96- 1 ) # Set orientation to vertical
129+ self .native_instance .setOrientation (1 ) # Set orientation to vertical
97130 self .views = []
98131
99132 def add_view (self , view ):
100133 self .views .append (view )
101134 self .native_instance .addView (view .native_instance )
102135
103-
104136else :
105137 raise PlatformNotDetectedError ("Platform could not be detected or is unsupported." )
0 commit comments