Visitar URL original
Merge pull request #2 from flutter/master · chunhtai/packages@7bc8e73 · GitHub
Skip to content

Commit 7bc8e73

Browse files
authored
Merge pull request flutter#2 from flutter/master
Updating flutter fork
2 parents bdcbc2a + 4510df8 commit 7bc8e73

48 files changed

Lines changed: 2339 additions & 184 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/flutter/lib/src/cupertino/app.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class CupertinoApp extends StatefulWidget {
175175
///
176176
/// See also:
177177
///
178-
/// * <https://flutter.io/debugging/#performanceoverlay>
178+
/// * <https://flutter.dev/debugging/#performanceoverlay>
179179
final bool showPerformanceOverlay;
180180

181181
/// Turns on checkerboarding of raster cache images.

‎packages/flutter/lib/src/cupertino/date_picker.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
540540

541541
Widget _buildMinutePicker(double offAxisFraction, TransitionBuilder itemPositioningBuilder) {
542542
return CupertinoPicker(
543-
scrollController: FixedExtentScrollController(initialItem: selectedMinute),
543+
scrollController: FixedExtentScrollController(initialItem: selectedMinute ~/ widget.minuteInterval),
544544
offAxisFraction: offAxisFraction,
545545
itemExtent: _kItemExtent,
546546
useMagnifier: _kUseMagnifier,

‎packages/flutter/lib/src/cupertino/dialog.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ bool _isInAccessibilityMode(BuildContext context) {
125125
/// * [CupertinoPopupSurface], which is a generic iOS-style popup surface that
126126
/// holds arbitrary content to create custom popups.
127127
/// * [CupertinoDialogAction], which is an iOS-style dialog button.
128+
/// * [AlertDialog], a Material Design alert dialog.
128129
/// * <https://developer.apple.com/ios/human-interface-guidelines/views/alerts/>
129130
class CupertinoAlertDialog extends StatelessWidget {
130131
/// Creates an iOS-style alert dialog.

‎packages/flutter/lib/src/cupertino/nav_bar.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ class CupertinoNavigationBarBackButton extends StatelessWidget {
12311231
Widget build(BuildContext context) {
12321232
final ModalRoute<dynamic> currentRoute = ModalRoute.of(context);
12331233
assert(
1234-
currentRoute.canPop,
1234+
currentRoute?.canPop == true,
12351235
'CupertinoNavigationBarBackButton should only be used in routes that can be popped',
12361236
);
12371237

‎packages/flutter/lib/src/cupertino/page_scaffold.dart‎

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'theme.dart';
1616
/// * [CupertinoTabScaffold], a similar widget for tabbed applications.
1717
/// * [CupertinoPageRoute], a modal page route that typically hosts a
1818
/// [CupertinoPageScaffold] with support for iOS-style page transitions.
19-
class CupertinoPageScaffold extends StatelessWidget {
19+
class CupertinoPageScaffold extends StatefulWidget {
2020
/// Creates a layout for pages with a navigation bar at the top.
2121
const CupertinoPageScaffold({
2222
Key key,
@@ -34,7 +34,8 @@ class CupertinoPageScaffold extends StatelessWidget {
3434
/// If translucent, the main content may slide behind it.
3535
/// Otherwise, the main content's top margin will be offset by its height.
3636
///
37-
/// The scaffold assumes the navigation bar will consume the [MediaQuery] top padding.
37+
/// The scaffold assumes the navigation bar will account for the [MediaQuery] top padding,
38+
/// also consume it if the navigation bar is opaque.
3839
// TODO(xster): document its page transition animation when ready
3940
final ObstructingPreferredSizeWidget navigationBar;
4041

@@ -60,44 +61,66 @@ class CupertinoPageScaffold extends StatelessWidget {
6061
/// Defaults to true and cannot be null.
6162
final bool resizeToAvoidBottomInset;
6263

64+
@override
65+
_CupertinoPageScaffoldState createState() => _CupertinoPageScaffoldState();
66+
}
67+
68+
class _CupertinoPageScaffoldState extends State<CupertinoPageScaffold> {
69+
final ScrollController _primaryScrollController = ScrollController();
70+
71+
void _handleStatusBarTap() {
72+
// Only act on the scroll controller if it has any attached scroll positions.
73+
if (_primaryScrollController.hasClients) {
74+
_primaryScrollController.animateTo(
75+
0.0,
76+
// Eyeballed from iOS.
77+
duration: const Duration(milliseconds: 500),
78+
curve: Curves.linearToEaseOut,
79+
);
80+
}
81+
}
82+
6383
@override
6484
Widget build(BuildContext context) {
6585
final List<Widget> stacked = <Widget>[];
6686

67-
Widget paddedContent = child;
68-
if (navigationBar != null) {
69-
final MediaQueryData existingMediaQuery = MediaQuery.of(context);
87+
Widget paddedContent = widget.child;
7088

89+
final MediaQueryData existingMediaQuery = MediaQuery.of(context);
90+
if (widget.navigationBar != null) {
7191
// TODO(xster): Use real size after partial layout instead of preferred size.
7292
// https://github.com/flutter/flutter/issues/12912
7393
final double topPadding =
74-
navigationBar.preferredSize.height + existingMediaQuery.padding.top;
94+
widget.navigationBar.preferredSize.height + existingMediaQuery.padding.top;
7595

7696
// Propagate bottom padding and include viewInsets if appropriate
77-
final double bottomPadding = resizeToAvoidBottomInset
97+
final double bottomPadding = widget.resizeToAvoidBottomInset
7898
? existingMediaQuery.viewInsets.bottom
7999
: 0.0;
80100

81-
final EdgeInsets newViewInsets = resizeToAvoidBottomInset
101+
final EdgeInsets newViewInsets = widget.resizeToAvoidBottomInset
82102
// The insets are consumed by the scaffolds and no longer exposed to
83103
// the descendant subtree.
84104
? existingMediaQuery.viewInsets.copyWith(bottom: 0.0)
85105
: existingMediaQuery.viewInsets;
86106

87107
final bool fullObstruction =
88-
navigationBar.fullObstruction ?? CupertinoTheme.of(context).barBackgroundColor.alpha == 0xFF;
108+
widget.navigationBar.fullObstruction ?? CupertinoTheme.of(context).barBackgroundColor.alpha == 0xFF;
89109

90110
// If navigation bar is opaquely obstructing, directly shift the main content
91111
// down. If translucent, let main content draw behind navigation bar but hint the
92112
// obstructed area.
93113
if (fullObstruction) {
94114
paddedContent = MediaQuery(
95-
data: existingMediaQuery.copyWith(
115+
data: existingMediaQuery
116+
// If the navigation bar is opaque, the top media query padding is fully consumed by the navigation bar.
117+
.removePadding(removeTop: true)
118+
.copyWith(
96119
viewInsets: newViewInsets,
97120
),
98121
child: Padding(
99122
padding: EdgeInsets.only(top: topPadding, bottom: bottomPadding),
100-
child: child,
123+
child: paddedContent,
101124
),
102125
);
103126
} else {
@@ -110,27 +133,44 @@ class CupertinoPageScaffold extends StatelessWidget {
110133
),
111134
child: Padding(
112135
padding: EdgeInsets.only(bottom: bottomPadding),
113-
child: child,
136+
child: paddedContent,
114137
),
115138
);
116139
}
117140
}
118141

119142
// The main content being at the bottom is added to the stack first.
120-
stacked.add(paddedContent);
143+
stacked.add(PrimaryScrollController(
144+
controller: _primaryScrollController,
145+
child: paddedContent,
146+
));
121147

122-
if (navigationBar != null) {
148+
if (widget.navigationBar != null) {
123149
stacked.add(Positioned(
124150
top: 0.0,
125151
left: 0.0,
126152
right: 0.0,
127-
child: navigationBar,
153+
child: widget.navigationBar,
128154
));
129155
}
130156

157+
// Add a touch handler the size of the status bar on top of all contents
158+
// to handle scroll to top by status bar taps.
159+
stacked.add(Positioned(
160+
top: 0.0,
161+
left: 0.0,
162+
right: 0.0,
163+
height: existingMediaQuery.padding.top,
164+
child: GestureDetector(
165+
excludeFromSemantics: true,
166+
onTap: _handleStatusBarTap,
167+
),
168+
),
169+
);
170+
131171
return DecoratedBox(
132172
decoration: BoxDecoration(
133-
color: backgroundColor ?? CupertinoTheme.of(context).scaffoldBackgroundColor,
173+
color: widget.backgroundColor ?? CupertinoTheme.of(context).scaffoldBackgroundColor,
134174
),
135175
child: Stack(
136176
children: stacked,

‎packages/flutter/lib/src/cupertino/route.dart‎

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,19 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
180180
return nextRoute is CupertinoPageRoute && !nextRoute.fullscreenDialog;
181181
}
182182

183-
@override
184-
void dispose() {
185-
_popGestureInProgress.remove(this);
186-
super.dispose();
187-
}
188-
189-
/// True if a Cupertino pop gesture is currently underway for [route].
183+
/// True if an iOS-style back swipe pop gesture is currently underway for [route].
184+
///
185+
/// This just check the route's [NavigatorState.userGestureInProgress].
190186
///
191187
/// See also:
192188
///
193189
/// * [popGestureEnabled], which returns true if a user-triggered pop gesture
194190
/// would be allowed.
195-
static bool isPopGestureInProgress(PageRoute<dynamic> route) => _popGestureInProgress.contains(route);
196-
static final Set<PageRoute<dynamic>> _popGestureInProgress = <PageRoute<dynamic>>{};
191+
static bool isPopGestureInProgress(PageRoute<dynamic> route) {
192+
return route.navigator.userGestureInProgress;
193+
}
197194

198-
/// True if a Cupertino pop gesture is currently underway for this route.
195+
/// True if an iOS-style back swipe pop gesture is currently underway for this route.
199196
///
200197
/// See also:
201198
///
@@ -233,10 +230,15 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
233230
if (route.fullscreenDialog)
234231
return false;
235232
// If we're in an animation already, we cannot be manually swiped.
236-
if (route.controller.status != AnimationStatus.completed)
233+
if (route.animation.status != AnimationStatus.completed)
234+
return false;
235+
// If we're being popped into, we also cannot be swiped until the pop above
236+
// it completes. This translates to our secondary animation being
237+
// dismissed.
238+
if (route.secondaryAnimation.status != AnimationStatus.dismissed)
237239
return false;
238240
// If we're in a gesture already, we cannot start another.
239-
if (_popGestureInProgress.contains(route))
241+
if (isPopGestureInProgress(route))
240242
return false;
241243

242244
// Looks like a back gesture would be welcome!
@@ -266,9 +268,7 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
266268
// gesture is detected. The returned controller handles all of the subsequent
267269
// drag events.
268270
static _CupertinoBackGestureController<T> _startPopGesture<T>(PageRoute<T> route) {
269-
assert(!_popGestureInProgress.contains(route));
270271
assert(_isPopGestureEnabled(route));
271-
_popGestureInProgress.add(route);
272272

273273
_CupertinoBackGestureController<T> backController;
274274
backController = _CupertinoBackGestureController<T>(
@@ -277,7 +277,6 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
277277
onEnded: () {
278278
backController?.dispose();
279279
backController = null;
280-
_popGestureInProgress.remove(route);
281280
},
282281
);
283282
return backController;
@@ -313,9 +312,12 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
313312
return CupertinoPageTransition(
314313
primaryRouteAnimation: animation,
315314
secondaryRouteAnimation: secondaryAnimation,
315+
// Check if the route has an animation that's currently participating
316+
// in a back swipe gesture.
317+
//
316318
// In the middle of a back gesture drag, let the transition be linear to
317319
// match finger motions.
318-
linearTransition: _popGestureInProgress.contains(route),
320+
linearTransition: isPopGestureInProgress(route),
319321
child: _CupertinoBackGestureDetector<T>(
320322
enabledCallback: () => _isPopGestureEnabled<T>(route),
321323
onStartPopGesture: () => _startPopGesture<T>(route),
@@ -354,28 +356,38 @@ class CupertinoPageTransition extends StatelessWidget {
354356
@required this.child,
355357
@required bool linearTransition,
356358
}) : assert(linearTransition != null),
357-
_primaryPositionAnimation = (linearTransition ? primaryRouteAnimation :
358-
// The curves below have been rigorously derived from plots of native
359-
// iOS animation frames. Specifically, a video was taken of a page
360-
// transition animation and the distance in each frame that the page
361-
// moved was measured. A best fit bezier curve was the fitted to the
362-
// point set, which is linearToEaseIn. Conversely, easeInToLinear is the
363-
// reflection over the origin of linearToEaseIn.
364-
CurvedAnimation(
365-
parent: primaryRouteAnimation,
366-
curve: Curves.linearToEaseOut,
367-
reverseCurve: Curves.easeInToLinear,
368-
)
369-
).drive(_kRightMiddleTween),
370-
_secondaryPositionAnimation = CurvedAnimation(
371-
parent: secondaryRouteAnimation,
372-
curve: Curves.linearToEaseOut,
373-
reverseCurve: Curves.easeInToLinear,
374-
).drive(_kMiddleLeftTween),
375-
_primaryShadowAnimation = CurvedAnimation(
376-
parent: primaryRouteAnimation,
377-
curve: Curves.linearToEaseOut,
378-
).drive(_kGradientShadowTween),
359+
_primaryPositionAnimation =
360+
(linearTransition
361+
? primaryRouteAnimation
362+
: CurvedAnimation(
363+
// The curves below have been rigorously derived from plots of native
364+
// iOS animation frames. Specifically, a video was taken of a page
365+
// transition animation and the distance in each frame that the page
366+
// moved was measured. A best fit bezier curve was the fitted to the
367+
// point set, which is linearToEaseIn. Conversely, easeInToLinear is the
368+
// reflection over the origin of linearToEaseIn.
369+
parent: primaryRouteAnimation,
370+
curve: Curves.linearToEaseOut,
371+
reverseCurve: Curves.easeInToLinear,
372+
)
373+
).drive(_kRightMiddleTween),
374+
_secondaryPositionAnimation =
375+
(linearTransition
376+
? secondaryRouteAnimation
377+
: CurvedAnimation(
378+
parent: secondaryRouteAnimation,
379+
curve: Curves.linearToEaseOut,
380+
reverseCurve: Curves.easeInToLinear,
381+
)
382+
).drive(_kMiddleLeftTween),
383+
_primaryShadowAnimation =
384+
(linearTransition
385+
? primaryRouteAnimation
386+
: CurvedAnimation(
387+
parent: primaryRouteAnimation,
388+
curve: Curves.linearToEaseOut,
389+
)
390+
).drive(_kGradientShadowTween),
379391
super(key: key);
380392

381393
// When this page is coming in to cover another page.
@@ -618,7 +630,6 @@ class _CupertinoBackGestureController<T> {
618630
animateForward = velocity > 0 ? false : true;
619631
else
620632
animateForward = controller.value > 0.5 ? true : false;
621-
622633
if (animateForward) {
623634
// The closer the panel is to dismissing, the shorter the animation is.
624635
// We want to cap the animation time, but we want to use a linear curve
@@ -650,9 +661,9 @@ class _CupertinoBackGestureController<T> {
650661
controller.removeStatusListener(_handleStatusChanged);
651662
}
652663
_animating = false;
664+
onEnded();
653665
if (status == AnimationStatus.dismissed)
654-
route.navigator.removeRoute(route); // this will cause the route to get disposed, which will dispose us
655-
onEnded(); // this will call dispose if popping the route failed to do so
666+
route.navigator.removeRoute(route); // This also disposes the route.
656667
}
657668

658669
void dispose() {

0 commit comments

Comments
 (0)