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

Commit 2d12f28

Browse files
authored
Merge pull request #278 from IIzzaya/hook1.5.4
[1.5.4] Add Cupertino basic.
2 parents c253cd1 + feb23af commit 2d12f28

23 files changed

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

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)