Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public <T extends FlutterFragment> T build() {
// Delegate that runs all lifecycle and OS hook logic that is common between
// FlutterActivity and FlutterFragment. See the FlutterActivityAndFragmentDelegate
// implementation for details about why it exists.
@VisibleForTesting @Nullable /* package */ FlutterActivityAndFragmentDelegate delegate;
@VisibleForTesting @Nullable protected FlutterActivityAndFragmentDelegate delegate;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment flutter/flutter#93905 (comment)

I don't think this is the right fix

Copy link
Member Author

@0xZOne 0xZOne Dec 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated in the comments flutter/flutter#93905 (comment), there are practical demands.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead expose the method we actually need to subclasses.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead expose the method we actually need to subclasses.

Thank you for your reply.

In this case, I think exposing the delegate of FlutterFragment as a protected member to subclasses is the least costly solution.


private final OnBackPressedCallback onBackPressedCallback =
new OnBackPressedCallback(true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding.OnSaveInstanceStateListener;
import io.flutter.plugins.GeneratedPluginRegistrant;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -466,6 +468,19 @@ public void fullyDrawn() {
}
}

@Test
public void itCanBeAccessibleFromSubclass() {
// To ensure that FlutterActivityAndFragmentDelegate is
// accessible to FlutterActivity subclasses.
try {
Field field = FlutterActivity.class.getDeclaredField("delegate");
field.setAccessible(true);
assertTrue(Modifier.isProtected(field.getModifiers()));
} catch (Exception e) {
assertTrue(false);
}
}

static class FlutterActivityWithProvidedEngine extends FlutterActivity {
@Override
@SuppressLint("MissingSuperCall")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.FlutterJNI;
import io.flutter.embedding.engine.loader.FlutterLoader;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -221,4 +223,17 @@ public void handleOnBackPressed() {
verify(mockDelegate, never()).onBackPressed();
assertTrue(onBackPressedCalled.get());
}

@Test
public void itCanBeAccessibleFromSubclass() {
// To ensure that FlutterActivityAndFragmentDelegate is
// accessible to FlutterFragment subclasses.
try {
Field field = FlutterFragment.class.getDeclaredField("delegate");
field.setAccessible(true);
assertTrue(Modifier.isProtected(field.getModifiers()));
} catch (Exception e) {
assertTrue(false);
}
}
}