This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[PlatformView][Android]VirtualDisplay resize on Android31 and above #47946
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
75d1fe7
[PlatformView][Android]VirtualDisplay resize on Android31 and above(#…
designDo d1c12da
add import
designDo 7a1c649
Code format
designDo 950afdd
Code format
designDo 228be10
Code format
designDo afe1b13
add TargetAPI 21
designDo ccda5a7
Merge branch 'main' into pre/128920
designDo 5e10d6e
Merge branch 'main' into pre/128920
designDo f29bcf9
Merge branch 'main' into pre/128920
designDo f5abcd3
Fixed review code
designDo f6c61ee
Merge branch 'main' into pre/128920
designDo 5391593
Merge branch 'main' into pre/128920
designDo ba38dca
Merge branch 'main' into pre/128920
designDo f000fe0
remove meaningless comments and add add onNewSizeFrameAvailable call…
designDo 8b2f684
Merge branch 'main' into pre/128920
designDo 502bab9
remove meaningless comments
designDo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import android.content.Context; | ||
import android.hardware.display.DisplayManager; | ||
import android.hardware.display.VirtualDisplay; | ||
import android.os.Build; | ||
import android.util.DisplayMetrics; | ||
import android.view.MotionEvent; | ||
import android.view.View; | ||
|
@@ -128,6 +129,16 @@ public int getRenderTargetHeight() { | |
} | ||
|
||
public void resize(final int width, final int height, final Runnable onNewSizeFrameAvailable) { | ||
// When 'hot reload', although the resize method is triggered, the size of the native View has | ||
// not changed. | ||
if (width == getRenderTargetWidth() && height == getRenderTargetHeight()) { | ||
getView().postDelayed(onNewSizeFrameAvailable, 0); | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After reading the calling code, we do need to run the onNewSizeFrameAvailable in this case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meaningless comments have been removed. |
||
} | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
resize31(getView(), width, height, onNewSizeFrameAvailable); | ||
return; | ||
} | ||
boolean isFocused = getView().isFocused(); | ||
final SingleViewPresentation.PresentationState presentationState = presentation.detachState(); | ||
// We detach the surface to prevent it being destroyed when releasing the vd. | ||
|
@@ -199,6 +210,15 @@ public void dispose() { | |
renderTarget.release(); | ||
} | ||
|
||
@TargetApi(31) | ||
private void resize31( | ||
View embeddedView, int width, int height, final Runnable onNewSizeFrameAvailable) { | ||
renderTarget.resize(width, height); | ||
// On Android versions 31+ resizing of a Virtual Display's Presentation is natively supported. | ||
virtualDisplay.resize(width, height, densityDpi); | ||
embeddedView.postDelayed(onNewSizeFrameAvailable, 0); | ||
} | ||
|
||
/** See {@link PlatformView#onFlutterViewAttached(View)} */ | ||
/*package*/ void onFlutterViewAttached(@NonNull View flutterView) { | ||
if (presentation == null || presentation.getView() == null) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the contract around onNewSizeFrameAvailable? In the case that the size doesn't change do we need to run it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,
postDelayed
can be removedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is true, it must be called.