Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly layout the WebView #9923

Merged
merged 2 commits into from
Sep 7, 2022
Merged

Correctly layout the WebView #9923

merged 2 commits into from
Sep 7, 2022

Conversation

mattleibow
Copy link
Member

@mattleibow mattleibow commented Sep 5, 2022

Description of Change

Correctly layout the WebView without always expanding to fit page contents.

It appears that Xamarin.Forms also used the parameters in this PR:
https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Platform.Android/Renderers/WebViewRenderer.cs#L137

Issues Fixed

Workaround

A workaround for now is to catch the native view when it is loaded and set the layout parameters for Android:

<WebView Source="https://www.youtube.com/watch?v=LXZfrnBasNU" Loaded="WebView_Loaded" />
private void WebView_Loaded(object sender, EventArgs e)
{
#if ANDROID
    var view = sender as WebView;
    var handler = view.Handler;
    var webview = handler?.PlatformView as Android.Webkit.WebView;
    if (webview is not null)
    {
        webview.LayoutParameters = new(
            Android.Views.ViewGroup.LayoutParams.MatchParent,
            Android.Views.ViewGroup.LayoutParams.MatchParent);

    }
#endif

@mattleibow mattleibow changed the title Dev/fix webview Correctly layout the WebView Sep 5, 2022
@mattleibow mattleibow added this to the .NET 6 + Servicing milestone Sep 5, 2022
@@ -25,7 +25,7 @@ protected override AWebView CreatePlatformView()
{
var platformView = new MauiWebView(this, Context!)
{
LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent)
LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
Copy link
Member

Choose a reason for hiding this comment

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

Does this cause any weirdness now if you have the WebView in a VerticalStackLayout?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I could see. I tried a piece of html that was 1 line and it seemed to size the web view to be 1 line. What was the reason to change this from forms?

@rmarinho rmarinho merged commit cad2885 into release/6.0.5xx-sr5 Sep 7, 2022
@rmarinho rmarinho deleted the dev/fix-webview branch September 7, 2022 10:35
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Jul 10, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants