@@ -143,6 +143,11 @@ typedef _GetSheetDragged = bool Function();
143143/// When `showDragHandle` is set to `true` , then a drag handle will be placed at
144144/// the top of the sheet. This flag will default to false.
145145///
146+ /// The `hasPlatformViews` parameter should be set to `true` when the sheet or
147+ /// the route underneath it contains a platform view that is composited by the
148+ /// host platform. See [CupertinoSheetTransition.hasPlatformViews] for
149+ /// platform-specific details.
150+ ///
146151/// iOS sheet widgets are generally designed to be tightly coupled to the context
147152/// of the widget that opened the sheet. As such, it is not recommended to push
148153/// a non-sheet route that covers the sheet without first popping the sheet. If
@@ -194,6 +199,7 @@ Future<T?> showCupertinoSheet<T>({
194199 RouteSettings ? settings,
195200 double ? topGap,
196201 bool showDragHandle = false ,
202+ bool hasPlatformViews = false ,
197203}) {
198204 assert (topGap == null || (topGap >= 0.0 && topGap <= 0.9 ), 'topGap must be between 0.0 and 0.9' );
199205 assert (pageBuilder != null || builder != null || scrollableBuilder != null );
@@ -211,6 +217,7 @@ Future<T?> showCupertinoSheet<T>({
211217 settings: settings,
212218 enableDrag: enableDrag,
213219 topGap: topGap,
220+ hasPlatformViews: hasPlatformViews,
214221 );
215222
216223 return Navigator .of (context, rootNavigator: true ).push <T >(route);
@@ -255,6 +262,7 @@ Future<T?> showCupertinoSheet<T>({
255262 settings: settings,
256263 enableDrag: enableDrag,
257264 topGap: topGap,
265+ hasPlatformViews: hasPlatformViews,
258266 );
259267 return Navigator .of (context, rootNavigator: true ).push <T >(route);
260268 }
@@ -273,6 +281,7 @@ class CupertinoSheetTransition extends StatefulWidget {
273281 required this .secondaryRouteAnimation,
274282 required this .child,
275283 required this .linearTransition,
284+ this .hasPlatformViews = false ,
276285 this .topGap = _kTopGapRatio,
277286 });
278287
@@ -304,21 +313,61 @@ class CupertinoSheetTransition extends StatefulWidget {
304313 /// {@endtemplate}
305314 final double topGap;
306315
316+ /// {@template cupertino_ui.CupertinoSheetTransition.hasPlatformViews}
317+ /// Whether the sheet or the route underneath it contains a platform view
318+ /// that is composited by the host platform.
319+ ///
320+ /// On iOS and macOS, set this to `true` when the sheet or the route underneath
321+ /// it contains a platform view. On Android, this flag is generally not needed
322+ /// unless the platform view uses a native-view composition mode such as hybrid
323+ /// composition.
324+ ///
325+ /// When set to `false` (the default), the transition uses image-filtered
326+ /// scaling for high-quality rendering. This can cause a native-composited
327+ /// platform view to appear detached from the rest of the route. Set this to
328+ /// `true` to keep it synchronized with the rest of the transition.
329+ /// {@endtemplate}
330+ final bool hasPlatformViews;
331+
332+ static Widget _delegateTransitionWithPlatformViews (
333+ BuildContext context,
334+ Animation <double > animation,
335+ Animation <double > secondaryAnimation,
336+ bool allowSnapshotting,
337+ Widget ? child,
338+ ) => delegateTransition (
339+ context,
340+ animation,
341+ secondaryAnimation,
342+ allowSnapshotting,
343+ child,
344+ hasPlatformViews: true ,
345+ );
346+
307347 /// The primary delegated transition. Will slide a non [CupertinoSheetRoute] page down.
308348 ///
309349 /// Provided to the previous route to coordinate transitions between routes.
310350 ///
311351 /// If a [CupertinoSheetRoute] already exists in the stack, then it will
312352 /// slide the previous sheet upwards instead.
353+ ///
354+ /// Set [hasPlatformViews] to `true` when the sheet or the route underneath it
355+ /// contains a platform view that is composited by the host platform. See
356+ /// [CupertinoSheetTransition.hasPlatformViews] for platform-specific details.
313357 static Widget delegateTransition (
314358 BuildContext context,
315359 Animation <double > animation,
316360 Animation <double > secondaryAnimation,
317361 bool allowSnapshotting,
318- Widget ? child,
319- ) {
362+ Widget ? child, {
363+ bool hasPlatformViews = false ,
364+ }) {
320365 if (CupertinoSheetRoute .hasParentSheet (context)) {
321- return _delegatedCoverSheetSecondaryTransition (secondaryAnimation, child);
366+ return _delegatedCoverSheetSecondaryTransition (
367+ secondaryAnimation,
368+ child,
369+ hasPlatformViews: hasPlatformViews,
370+ );
322371 }
323372 final bool linear = Navigator .of (context).userGestureInProgress;
324373
@@ -377,7 +426,12 @@ class CupertinoSheetTransition extends StatefulWidget {
377426 position: slideAnimation,
378427 child: ScaleTransition (
379428 scale: scaleAnimation,
380- filterQuality: FilterQuality .medium,
429+ // During animation, FilterQuality.medium uses an ImageFilterLayer, which is
430+ // usually worthwhile for animated transforms and avoids the observed subpixel
431+ // drift. A null filter quality always uses a TransformLayer to keep platform
432+ // views synchronized with the host. When not animating, filterQuality is ignored
433+ // and both options have the same effect.
434+ filterQuality: hasPlatformViews ? null : FilterQuality .medium,
381435 alignment: Alignment .topCenter,
382436 child: AnimatedBuilder (
383437 animation: radiusAnimation,
@@ -399,8 +453,9 @@ class CupertinoSheetTransition extends StatefulWidget {
399453
400454 static Widget _delegatedCoverSheetSecondaryTransition (
401455 Animation <double > secondaryAnimation,
402- Widget ? child,
403- ) {
456+ Widget ? child, {
457+ bool hasPlatformViews = false ,
458+ }) {
404459 const Curve curve = Curves .linearToEaseOut;
405460 const Curve reverseCurve = Curves .easeInToLinear;
406461 final curvedAnimation = CurvedAnimation (
@@ -418,7 +473,7 @@ class CupertinoSheetTransition extends StatefulWidget {
418473 transformHitTests: false ,
419474 child: ScaleTransition (
420475 scale: scaleAnimation,
421- filterQuality: FilterQuality .medium,
476+ filterQuality: hasPlatformViews ? null : FilterQuality .medium,
422477 alignment: Alignment .topCenter,
423478 child: ClipRSuperellipse (
424479 borderRadius: const BorderRadius .vertical (top: Radius .circular (12 )),
@@ -537,7 +592,7 @@ class _CupertinoSheetTransitionState extends State<CupertinoSheetTransition>
537592 transformHitTests: false ,
538593 child: ScaleTransition (
539594 scale: _secondaryScaleAnimation,
540- filterQuality: FilterQuality .medium,
595+ filterQuality: widget.hasPlatformViews ? null : FilterQuality .medium,
541596 alignment: Alignment .topCenter,
542597 child: child,
543598 ),
@@ -667,6 +722,7 @@ class CupertinoSheetRoute<T> extends PageRoute<T> with _CupertinoSheetRouteTrans
667722 this .scrollableBuilder,
668723 this .enableDrag = true ,
669724 this .showDragHandle = false ,
725+ this .hasPlatformViews = false ,
670726 double ? topGap,
671727 }) : assert (
672728 topGap == null || (topGap >= 0.0 && topGap <= 0.9 ),
@@ -712,6 +768,10 @@ class CupertinoSheetRoute<T> extends PageRoute<T> with _CupertinoSheetRouteTrans
712768 @override
713769 final bool enableDrag;
714770
771+ /// {@macro cupertino_ui.CupertinoSheetTransition.hasPlatformViews}
772+ @override
773+ final bool hasPlatformViews;
774+
715775 // The gap between the top of the screen and the top of the sheet.
716776 final double ? _topGap;
717777
@@ -850,7 +910,9 @@ mixin _CupertinoSheetRouteTransitionMixin<T> on PageRoute<T> {
850910 if (_hasCustomTopGap) {
851911 return null ;
852912 }
853- return CupertinoSheetTransition .delegateTransition;
913+ return hasPlatformViews
914+ ? CupertinoSheetTransition ._delegateTransitionWithPlatformViews
915+ : CupertinoSheetTransition .delegateTransition;
854916 }
855917
856918 /// Determines whether the content can be dragged.
@@ -864,6 +926,9 @@ mixin _CupertinoSheetRouteTransitionMixin<T> on PageRoute<T> {
864926 /// {@macro cupertino_ui.CupertinoSheetTransition.topGap}
865927 double get topGap;
866928
929+ /// {@macro cupertino_ui.CupertinoSheetTransition.hasPlatformViews}
930+ bool get hasPlatformViews;
931+
867932 /// Whether a custom top gap has been set.
868933 bool get _hasCustomTopGap;
869934
@@ -898,13 +963,15 @@ mixin _CupertinoSheetRouteTransitionMixin<T> on PageRoute<T> {
898963 Widget child,
899964 bool enableDrag,
900965 double topGap,
966+ bool hasPlatformViews,
901967 ) {
902968 final bool linearTransition = route.popGestureInProgress;
903969 return CupertinoSheetTransition (
904970 primaryRouteAnimation: animation,
905971 secondaryRouteAnimation: secondaryAnimation,
906972 linearTransition: linearTransition,
907973 topGap: topGap,
974+ hasPlatformViews: hasPlatformViews,
908975 child: _CupertinoDragGestureDetector <T >(
909976 enabledCallback: () => enableDrag,
910977 onStartPopGesture: () => _startPopGesture <T >(route, topGap),
@@ -941,6 +1008,7 @@ mixin _CupertinoSheetRouteTransitionMixin<T> on PageRoute<T> {
9411008 child,
9421009 enableDrag,
9431010 topGap,
1011+ hasPlatformViews,
9441012 );
9451013 }
9461014}
0 commit comments