Skip to content

Commit 53faef4

Browse files
committed
Merge remote-tracking branch 'origin/main' into macos-wide-gamut
2 parents fc1bd4e + 65b1ec4 commit 53faef4

10 files changed

Lines changed: 235 additions & 95 deletions

File tree

DEPS

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ vars = {
1515
'flutter_git': 'https://flutter.googlesource.com',
1616
'skia_git': 'https://skia.googlesource.com',
1717
'llvm_git': 'https://llvm.googlesource.com',
18-
'skia_revision': 'a5a535bc21a396cb144e261034e25d0c28a3dd59',
18+
'skia_revision': 'f37a22506eb4ea75892c53617a9e3db5a18c5cf7',
1919

2020
# WARNING: DO NOT EDIT canvaskit_cipd_instance MANUALLY
2121
# See `lib/web_ui/README.md` for how to roll CanvasKit to a new version.
@@ -59,7 +59,7 @@ vars = {
5959
# updated revision list of existing dependencies. You will need to
6060
# gclient sync before and after update deps to ensure all deps are updated.
6161
# updated revision list of existing dependencies.
62-
'dart_revision': 'cde322c518b9b1938092cf2fbd53c59e374fee60',
62+
'dart_revision': '1aa8f2de758701eec498544f60d076a9c4600516',
6363

6464
# WARNING: DO NOT EDIT MANUALLY
6565
# The lines between blank lines above and below are generated by a script. See create_updated_flutter_deps.py
@@ -75,7 +75,7 @@ vars = {
7575
'dart_perfetto_rev': '13ce0c9e13b0940d2476cd0cff2301708a9a2e2b',
7676
'dart_protobuf_gn_rev': 'ca669f79945418f6229e4fef89b666b2a88cbb10',
7777
'dart_protobuf_rev': '9e30258e0aa6a6430ee36c84b75308a9702fde42',
78-
'dart_pub_rev': 'db5c3c06b21098fcf7e9e5acb8a9e6f5dd15b2fe',
78+
'dart_pub_rev': 'ed2628f65de5d54922e2d34ebbcb1bafa8c93cc2',
7979
'dart_sync_http_rev': '6666fff944221891182e1f80bf56569338164d72',
8080
'dart_tools_rev': '93bf967097d251a4d43d4ae65ea047fe3e7f7fa7',
8181
'dart_vector_math_rev': '70a9a2cb610d040b247f3ca2cd70a94c1c6f6f23',
@@ -810,7 +810,7 @@ deps = {
810810
'packages': [
811811
{
812812
'package': 'fuchsia/sdk/core/linux-amd64',
813-
'version': 'nI52U4LJMrBv8G1M93nbUJdkBI-6InzLSUSkhVwybeIC'
813+
'version': '1L4m9qCikk-JzrNWEvOEUPSdOn3nnWOOM4azOtD23SQC'
814814
}
815815
],
816816
'condition': 'download_fuchsia_deps and not download_fuchsia_sdk',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
510dd407289a82257f538e2ec029263159bc0d16
1+
837dbbdf62dae7a22b403cdbbd8fcd9b1cb32be3

engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44

55
package io.flutter.embedding.android;
66

7+
import static io.flutter.Build.API_LEVELS;
8+
79
import android.app.Activity;
810
import android.content.ComponentCallbacks2;
911
import android.content.Context;
1012
import android.content.Intent;
13+
import android.os.Build;
1114
import android.os.Bundle;
1215
import android.view.LayoutInflater;
1316
import android.view.View;
1417
import android.view.ViewGroup;
1518
import android.view.ViewTreeObserver.OnWindowFocusChangeListener;
19+
import androidx.activity.BackEventCompat;
1620
import androidx.activity.OnBackPressedCallback;
1721
import androidx.annotation.NonNull;
1822
import androidx.annotation.Nullable;
23+
import androidx.annotation.RequiresApi;
1924
import androidx.annotation.VisibleForTesting;
2025
import androidx.fragment.app.Fragment;
2126
import androidx.fragment.app.FragmentActivity;
@@ -1011,13 +1016,40 @@ public FlutterActivityAndFragmentDelegate createDelegate(
10111016
}
10121017

10131018
@VisibleForTesting
1014-
final OnBackPressedCallback onBackPressedCallback =
1015-
new OnBackPressedCallback(true) {
1019+
final OnBackPressedCallback onBackPressedCallback = createOnBackPressedCallback();
1020+
1021+
private OnBackPressedCallback createOnBackPressedCallback() {
1022+
if (Build.VERSION.SDK_INT >= API_LEVELS.API_34) {
1023+
return new OnBackPressedCallback(true) {
10161024
@Override
10171025
public void handleOnBackPressed() {
1018-
onBackPressed();
1026+
commitBackGesture();
1027+
}
1028+
1029+
@Override
1030+
public void handleOnBackCancelled() {
1031+
cancelBackGesture();
1032+
}
1033+
1034+
@Override
1035+
public void handleOnBackProgressed(@NonNull BackEventCompat backEvent) {
1036+
updateBackGestureProgress(backEvent);
1037+
}
1038+
1039+
@Override
1040+
public void handleOnBackStarted(@NonNull BackEventCompat backEvent) {
1041+
startBackGesture(backEvent);
10191042
}
10201043
};
1044+
}
1045+
1046+
return new OnBackPressedCallback(true) {
1047+
@Override
1048+
public void handleOnBackPressed() {
1049+
onBackPressed();
1050+
}
1051+
};
1052+
}
10211053

10221054
public FlutterFragment() {
10231055
// Ensure that we at least have an empty Bundle of arguments so that we don't
@@ -1240,6 +1272,34 @@ public void onBackPressed() {
12401272
}
12411273
}
12421274

1275+
@RequiresApi(API_LEVELS.API_34)
1276+
public void startBackGesture(@NonNull BackEventCompat backEvent) {
1277+
if (stillAttachedForEvent("startBackGesture")) {
1278+
delegate.startBackGesture(backEvent.toBackEvent());
1279+
}
1280+
}
1281+
1282+
@RequiresApi(API_LEVELS.API_34)
1283+
public void updateBackGestureProgress(@NonNull BackEventCompat backEvent) {
1284+
if (stillAttachedForEvent("updateBackGestureProgress")) {
1285+
delegate.updateBackGestureProgress(backEvent.toBackEvent());
1286+
}
1287+
}
1288+
1289+
@RequiresApi(API_LEVELS.API_34)
1290+
public void commitBackGesture() {
1291+
if (stillAttachedForEvent("commitBackGesture")) {
1292+
delegate.commitBackGesture();
1293+
}
1294+
}
1295+
1296+
@RequiresApi(API_LEVELS.API_34)
1297+
public void cancelBackGesture() {
1298+
if (stillAttachedForEvent("cancelBackGesture")) {
1299+
delegate.cancelBackGesture();
1300+
}
1301+
}
1302+
12431303
/**
12441304
* A result has been returned after an invocation of {@link
12451305
* Fragment#startActivityForResult(Intent, int)}.

engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterFragmentTest.java

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919
import static org.mockito.Mockito.verify;
2020
import static org.mockito.Mockito.when;
2121

22+
import android.annotation.TargetApi;
2223
import android.content.Context;
24+
import androidx.activity.BackEventCompat;
2325
import androidx.activity.OnBackPressedCallback;
26+
import androidx.activity.OnBackPressedDispatcher;
2427
import androidx.fragment.app.FragmentActivity;
2528
import androidx.test.core.app.ActivityScenario;
2629
import androidx.test.core.app.ApplicationProvider;
2730
import androidx.test.ext.junit.runners.AndroidJUnit4;
31+
import io.flutter.Build;
2832
import io.flutter.embedding.engine.FlutterEngine;
2933
import io.flutter.embedding.engine.FlutterEngineCache;
3034
import io.flutter.embedding.engine.FlutterJNI;
@@ -34,6 +38,7 @@
3438
import java.util.concurrent.atomic.AtomicBoolean;
3539
import org.junit.Test;
3640
import org.junit.runner.RunWith;
41+
import org.robolectric.annotation.Config;
3742

3843
@RunWith(AndroidJUnit4.class)
3944
public class FlutterFragmentTest {
@@ -286,7 +291,9 @@ public void itReturnsExclusiveAppComponent() {
286291
}
287292

288293
@Test
289-
public void itDelegatesOnBackPressedWithSetFrameworkHandlesBack() {
294+
@Config(sdk = Build.API_LEVELS.API_33)
295+
@TargetApi(Build.API_LEVELS.API_33)
296+
public void itDelegatesOnBackPressedWithSetFrameworkHandlesBackForSdk33() {
290297
// We need to mock FlutterJNI to avoid triggering native code.
291298
FlutterJNI flutterJNI = mock(FlutterJNI.class);
292299
when(flutterJNI.isAttached()).thenReturn(true);
@@ -334,6 +341,72 @@ public void itDelegatesOnBackPressedWithSetFrameworkHandlesBack() {
334341
}
335342
}
336343

344+
@Test
345+
@Config(sdk = Build.API_LEVELS.API_34)
346+
@TargetApi(Build.API_LEVELS.API_34)
347+
public void itDelegatesOnBackPressedWithSetFrameworkHandlesBackForSdk34OrHigher() {
348+
// We need to mock FlutterJNI to avoid triggering native code.
349+
FlutterJNI flutterJNI = mock(FlutterJNI.class);
350+
when(flutterJNI.isAttached()).thenReturn(true);
351+
352+
FlutterEngine flutterEngine =
353+
new FlutterEngine(ctx, new FlutterLoader(), flutterJNI, null, false);
354+
FlutterEngineCache.getInstance().put("my_cached_engine", flutterEngine);
355+
356+
FlutterFragment fragment =
357+
FlutterFragment.withCachedEngine("my_cached_engine")
358+
// This enables the use of onBackPressedCallback, which is what
359+
// sends backs to the framework if setFrameworkHandlesBack is true.
360+
.shouldAutomaticallyHandleOnBackPressed(true)
361+
.build();
362+
363+
try (ActivityScenario<FragmentActivity> scenario =
364+
ActivityScenario.launch(FragmentActivity.class)) {
365+
scenario.onActivity(
366+
activity -> {
367+
activity
368+
.getSupportFragmentManager()
369+
.beginTransaction()
370+
.add(android.R.id.content, fragment)
371+
.commitNow();
372+
373+
FlutterActivityAndFragmentDelegate mockDelegate =
374+
mock(FlutterActivityAndFragmentDelegate.class);
375+
isDelegateAttached = true;
376+
when(mockDelegate.isAttached()).thenAnswer(invocation -> isDelegateAttached);
377+
doAnswer(invocation -> isDelegateAttached = false).when(mockDelegate).onDetach();
378+
TestDelegateFactory delegateFactory = new TestDelegateFactory(mockDelegate);
379+
fragment.setDelegateFactory(delegateFactory);
380+
381+
BackEventCompat mockBackEvent = mock(BackEventCompat.class);
382+
OnBackPressedDispatcher dispatcher = activity.getOnBackPressedDispatcher();
383+
384+
// Back gesture events now will still be handled by Android (the default),
385+
// until setFrameworkHandlesBack is set to true.
386+
dispatcher.dispatchOnBackStarted(mockBackEvent);
387+
dispatcher.dispatchOnBackProgressed(mockBackEvent);
388+
dispatcher.onBackPressed();
389+
dispatcher.dispatchOnBackCancelled();
390+
verify(mockDelegate, times(0)).startBackGesture(any());
391+
verify(mockDelegate, times(0)).updateBackGestureProgress(any());
392+
verify(mockDelegate, times(0)).commitBackGesture();
393+
verify(mockDelegate, times(0)).cancelBackGesture();
394+
395+
// Setting setFrameworkHandlesBack to true means the delegate will receive
396+
// the back and Android won't handle it.
397+
fragment.setFrameworkHandlesBack(true);
398+
dispatcher.dispatchOnBackStarted(mockBackEvent);
399+
dispatcher.dispatchOnBackProgressed(mockBackEvent);
400+
dispatcher.onBackPressed();
401+
dispatcher.dispatchOnBackCancelled();
402+
verify(mockDelegate, times(1)).startBackGesture(any());
403+
verify(mockDelegate, times(1)).updateBackGestureProgress(any());
404+
verify(mockDelegate, times(1)).commitBackGesture();
405+
verify(mockDelegate, times(1)).cancelBackGesture();
406+
});
407+
}
408+
}
409+
337410
@Test
338411
public void itHandlesPopSystemNavigationAutomaticallyWhenEnabled() {
339412
// We need to mock FlutterJNI to avoid triggering native code.

examples/api/lib/widgets/sliver/decorated_sliver.0.dart

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,6 @@ class SliverDecorationExample extends StatelessWidget {
3333
return CustomScrollView(
3434
slivers: <Widget>[
3535
DecoratedSliver(
36-
key: const ValueKey<String>('radial-gradient'),
37-
decoration: const BoxDecoration(
38-
gradient: RadialGradient(
39-
center: Alignment(-0.5, -0.6),
40-
radius: 0.15,
41-
colors: <Color>[Color(0xFFEEEEEE), Color(0xFF111133)],
42-
stops: <double>[0.4, 0.8],
43-
),
44-
),
45-
sliver: SliverList.list(
46-
children: <Widget>[
47-
SizedBox(
48-
height: 200.0,
49-
child: Center(
50-
child: Text(
51-
'A moon on a night sky',
52-
style: Theme.of(context).textTheme.titleLarge,
53-
),
54-
),
55-
),
56-
],
57-
),
58-
),
59-
DecoratedSliver(
60-
key: const ValueKey<String>('linear-gradient'),
6136
decoration: const BoxDecoration(
6237
gradient: LinearGradient(
6338
begin: Alignment.topCenter,
@@ -74,19 +49,42 @@ class SliverDecorationExample extends StatelessWidget {
7449
],
7550
),
7651
),
77-
sliver: SliverList.list(
78-
children: <Widget>[
79-
SizedBox(
80-
height: 500.0,
52+
sliver: SliverMainAxisGroup(
53+
slivers: <Widget>[
54+
SliverToBoxAdapter(
8155
child: Container(
82-
alignment: Alignment.topCenter,
83-
padding: const EdgeInsets.only(top: 56.0),
84-
child: Text(
85-
'A blue sky',
86-
style: Theme.of(context).textTheme.titleLarge,
56+
height: 200.0,
57+
decoration: const BoxDecoration(
58+
gradient: RadialGradient(
59+
center: Alignment(-0.5, -0.6),
60+
radius: 0.15,
61+
colors: <Color>[Color(0xFFEEEEEE), Color(0xFF111133)],
62+
stops: <double>[0.4, 0.8],
63+
),
64+
),
65+
child: Center(
66+
child: Text(
67+
'A moon on a night sky',
68+
style: Theme.of(context).textTheme.titleLarge,
69+
),
8770
),
8871
),
8972
),
73+
SliverList.list(
74+
children: <Widget>[
75+
SizedBox(
76+
height: 500.0,
77+
child: Container(
78+
alignment: Alignment.topCenter,
79+
padding: const EdgeInsets.only(top: 56.0),
80+
child: Text(
81+
'A blue sky',
82+
style: Theme.of(context).textTheme.titleLarge,
83+
),
84+
),
85+
),
86+
],
87+
),
9088
],
9189
),
9290
),

0 commit comments

Comments
 (0)