Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit ef1c9e4

Browse files
committed
[1.5.4] Add Cupertino.
1 parent c253cd1 commit ef1c9e4

23 files changed

+2214
-18
lines changed

Runtime/cupertino.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/cupertino/app.cs

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
using System.Collections.Generic;
2+
using Unity.UIWidgets.foundation;
3+
using Unity.UIWidgets.painting;
4+
using Unity.UIWidgets.ui;
5+
using Unity.UIWidgets.widgets;
6+
7+
namespace Unity.UIWidgets.cupertino {
8+
public class CupertinoApp : StatefulWidget {
9+
public CupertinoApp(
10+
Key key = null,
11+
GlobalKey<NavigatorState> navigatorKey = null,
12+
Widget home = null,
13+
CupertinoThemeData theme = null,
14+
Dictionary<string, WidgetBuilder> routes = null,
15+
string initialRoute = null,
16+
RouteFactory onGenerateRoute = null,
17+
RouteFactory onUnknownRoute = null,
18+
List<NavigatorObserver> navigatorObservers = null,
19+
TransitionBuilder builder = null,
20+
string title = "",
21+
GenerateAppTitle onGenerateTitle = null,
22+
Color color = null,
23+
Locale locale = null,
24+
List<LocalizationsDelegate<CupertinoLocalizations>> localizationsDelegates = null,
25+
LocaleListResolutionCallback localeListResolutionCallback = null,
26+
LocaleResolutionCallback localeResolutionCallback = null,
27+
List<Locale> supportedLocales = null,
28+
bool showPerformanceOverlay = false,
29+
bool checkerboardRasterCacheImages = false,
30+
bool checkerboardOffscreenLayers = false,
31+
bool showSemanticsDebugger = false,
32+
bool debugShowCheckedModeBanner = true
33+
) : base(key: key) {
34+
D.assert(routes != null);
35+
D.assert(navigatorObservers != null);
36+
D.assert(title != null);
37+
D.assert(showPerformanceOverlay != null);
38+
D.assert(checkerboardRasterCacheImages != null);
39+
D.assert(checkerboardOffscreenLayers != null);
40+
D.assert(showSemanticsDebugger != null);
41+
D.assert(debugShowCheckedModeBanner != null);
42+
43+
supportedLocales = supportedLocales ?? new List<Locale> {new Locale("en", "US")};
44+
this.navigatorKey = navigatorKey;
45+
this.home = home;
46+
this.theme = theme;
47+
this.routes = routes ?? new Dictionary<string, WidgetBuilder>();
48+
this.initialRoute = initialRoute;
49+
this.onGenerateRoute = onGenerateRoute;
50+
this.onUnknownRoute = onUnknownRoute;
51+
this.navigatorObservers = navigatorObservers ?? new List<NavigatorObserver>();
52+
this.builder = builder;
53+
this.title = title;
54+
this.onGenerateTitle = onGenerateTitle;
55+
this.color = color;
56+
this.locale = locale;
57+
this.localizationsDelegates = localizationsDelegates;
58+
this.localeListResolutionCallback = localeListResolutionCallback;
59+
this.localeResolutionCallback = localeResolutionCallback;
60+
this.supportedLocales = supportedLocales;
61+
this.showPerformanceOverlay = showPerformanceOverlay;
62+
this.checkerboardRasterCacheImages = checkerboardRasterCacheImages;
63+
this.checkerboardOffscreenLayers = checkerboardOffscreenLayers;
64+
this.showSemanticsDebugger = showSemanticsDebugger;
65+
this.debugShowCheckedModeBanner = debugShowCheckedModeBanner;
66+
}
67+
68+
public readonly GlobalKey<NavigatorState> navigatorKey;
69+
public readonly Widget home;
70+
public readonly CupertinoThemeData theme;
71+
public readonly Dictionary<string, WidgetBuilder> routes;
72+
public readonly string initialRoute;
73+
public readonly RouteFactory onGenerateRoute;
74+
public readonly RouteFactory onUnknownRoute;
75+
public readonly List<NavigatorObserver> navigatorObservers;
76+
public readonly TransitionBuilder builder;
77+
public readonly string title;
78+
public readonly GenerateAppTitle onGenerateTitle;
79+
public readonly Color color;
80+
public readonly Locale locale;
81+
public readonly List<LocalizationsDelegate<CupertinoLocalizations>> localizationsDelegates;
82+
public readonly LocaleListResolutionCallback localeListResolutionCallback;
83+
public readonly LocaleResolutionCallback localeResolutionCallback;
84+
public readonly List<Locale> supportedLocales;
85+
public readonly bool showPerformanceOverlay;
86+
public readonly bool checkerboardRasterCacheImages;
87+
public readonly bool checkerboardOffscreenLayers;
88+
public readonly bool showSemanticsDebugger;
89+
public readonly bool debugShowCheckedModeBanner;
90+
91+
public override State createState() {
92+
return new _CupertinoAppState();
93+
}
94+
95+
public static HeroController createCupertinoHeroController() {
96+
return new HeroController();
97+
}
98+
}
99+
100+
101+
public class _AlwaysCupertinoScrollBehavior : ScrollBehavior {
102+
public override Widget buildViewportChrome(BuildContext context, Widget child, AxisDirection axisDirection) {
103+
return child;
104+
}
105+
106+
public override ScrollPhysics getScrollPhysics(BuildContext context) {
107+
return new BouncingScrollPhysics();
108+
}
109+
}
110+
111+
class _CupertinoAppState : State<CupertinoApp> {
112+
HeroController _heroController;
113+
114+
public override void initState() {
115+
base.initState();
116+
this._heroController = CupertinoApp.createCupertinoHeroController();
117+
this._updateNavigator();
118+
}
119+
120+
public override void didUpdateWidget(StatefulWidget oldWidget) {
121+
base.didUpdateWidget(oldWidget);
122+
if (this.widget.navigatorKey != ((CupertinoApp) oldWidget).navigatorKey) {
123+
this._heroController = CupertinoApp.createCupertinoHeroController();
124+
}
125+
126+
this._updateNavigator();
127+
}
128+
129+
List<NavigatorObserver> _navigatorObservers;
130+
131+
void _updateNavigator() {
132+
if (this.widget.home != null || this.widget.routes.isNotEmpty() || this.widget.onGenerateRoute != null ||
133+
this.widget.onUnknownRoute != null) {
134+
this._navigatorObservers = new List<NavigatorObserver>();
135+
foreach (var item in this.widget.navigatorObservers) {
136+
this._navigatorObservers.Add(item);
137+
}
138+
}
139+
else {
140+
this._navigatorObservers = new List<NavigatorObserver>();
141+
}
142+
}
143+
144+
List<LocalizationsDelegate> _localizationsDelegates {
145+
get {
146+
List<LocalizationsDelegate<CupertinoLocalizations>> _delegates =
147+
new List<LocalizationsDelegate<CupertinoLocalizations>>();
148+
if (this.widget.localizationsDelegates != null) {
149+
_delegates.AddRange(this.widget.localizationsDelegates);
150+
}
151+
152+
_delegates.Add(DefaultCupertinoLocalizations.del);
153+
return new List<LocalizationsDelegate>(_delegates);
154+
}
155+
}
156+
157+
public override Widget build(BuildContext context) {
158+
CupertinoThemeData effectiveThemeData = this.widget.theme ?? new CupertinoThemeData();
159+
160+
Widget _InspectorSelectButtonBuilder(BuildContext _context, VoidCallback onPressed) {
161+
return CupertinoButton.filled(
162+
child: new Icon(
163+
CupertinoIcons.search,
164+
size: 28.0f,
165+
color: CupertinoColors.white
166+
),
167+
padding: EdgeInsets.zero,
168+
onPressed: onPressed
169+
);
170+
}
171+
172+
return new ScrollConfiguration(
173+
behavior: new _AlwaysCupertinoScrollBehavior(),
174+
child: new CupertinoTheme(
175+
data: effectiveThemeData,
176+
child: new WidgetsApp(
177+
pageRouteBuilder: (RouteSettings settings, WidgetBuilder builder) =>
178+
new CupertinoPageRoute(settings: settings, builder: builder),
179+
home: this.widget.home,
180+
routes: this.widget.routes,
181+
initialRoute: this.widget.initialRoute,
182+
onGenerateRoute: this.widget.onGenerateRoute,
183+
onUnknownRoute: this.widget.onUnknownRoute,
184+
builder: this.widget.builder,
185+
title: this.widget.title,
186+
onGenerateTitle: this.widget.onGenerateTitle,
187+
textStyle: effectiveThemeData.textTheme.textStyle,
188+
color: this.widget.color ?? CupertinoColors.activeBlue,
189+
locale: this.widget.locale,
190+
localizationsDelegates: this._localizationsDelegates,
191+
localeResolutionCallback: this.widget.localeResolutionCallback,
192+
localeListResolutionCallback: this.widget.localeListResolutionCallback,
193+
supportedLocales: this.widget.supportedLocales,
194+
showPerformanceOverlay: this.widget.showPerformanceOverlay,
195+
checkerboardRasterCacheImages: this.widget.checkerboardRasterCacheImages,
196+
checkerboardOffscreenLayers: this.widget.checkerboardOffscreenLayers,
197+
showSemanticsDebugger: this.widget.showSemanticsDebugger,
198+
debugShowCheckedModeBanner: this.widget.debugShowCheckedModeBanner,
199+
inspectorSelectButtonBuilder: _InspectorSelectButtonBuilder
200+
)
201+
)
202+
);
203+
}
204+
}
205+
}

Runtime/cupertino/app.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)