Skip to content

Commit

Permalink
Renaming public APIs Native --> Platform (#4599)
Browse files Browse the repository at this point in the history
* Rename NativeView --> PlatformView

* Rename NativeImage --> PlatformImage

* Rename NativeArrange --> PlatformArrange

* Rename NativeTicker --> PlatformTicker

* Rename CreateNativeElement --> CreativePlatformElement

* Rename CreateNativeWindow --> CreatePlatformWindow

* Rename ToNative --> ToPlatform

* Rename "Native" properties in IVisualElementController

* Rename GetNativeSize --> GetPlatformSize

* Rename Slider NativeMaxValue --> PlatformMaxValue

* Rename CreateNativeControl --> CreatePlatformControl

* Rename GetNativeRecognizer --> GetPlatformRecognizer

* Rename ManageNativeControlLifetime --> ManagePlatformControlLifetime

* Rename UpdateNativeSelection --> UpdatePlatformSelection

* Rename UpdateNativeWidget --> UpdatePlatformWidget

* Rename NativeControl --> PlatformControl

* Rename NativeSelection --> PlatformSelection

* Rename CreateNativePullToRefresh --> CreatePlatformPullToRefresh

* Rename NativeHandler --> PlatformHandler

* Rename NativeVersion --> PlatformVersion, NativeApis --> PlatformApis

* Rename NativeElement --> PlatformElement and update related gradlew + generated code

* Rename files using NativeElement --> PlatformElement

* Rename NativeBinding --> PlatformBinding

* Rename NativeWrapper --> PlatformWrapper

* Rename NativeValue --> PlatformValue

* Rename NativeShape --> PlatformShape

* Rename NativeTicker --> PlatformTicker files

* Rename nativeApplication --> platformApplication

* Rename nativeWindow --> platformWindow

* Rename nativeButton --> platformButton

* Rename nativeCheckBox --> platformCheckBox

* Rename nativeDatePicker --> platformDatePicker

* Rename nativeLabel --> platformLabel

* Rename nativePicker --> platformPicker

* Rename nativeProgressBar --> platformProgressBar

* Rename nativeStepper --> platformStepper

* Rename nativeWebView --> platformWebView

* Rename nativeText --> platformText

* Rename nativeValue --> platformValue

* Rename nativeRadioButton --> platformRadioButton

* Rename nativePaint --> platformPaint

* Rename nativeControl --> platformControl

* Rename nativeApi --> platformApi

* Rename nativeCell --> platformCell

* Rename nativeView --> platformView

* Fix renames that were missed in previous commits

* Fix a couple more renames and bad merges

* Rebase and rename again

* Rename NativeView --> PlatformView

* Rename ToNative --> ToPlatform

* Rename nativeStepper --> platformStepper

* Rename nativeRadioButton --> platformRadioButton

* Rename nativeControl --> platformControl

* Rename nativeView --> platformView

* Fix a couple more renames and bad merges

* Add missing parenthesis

* Rename NativeColor --> PlatformColor

* Rename NativeLabel --> PlatformLabel

* Rename NativeCell --> PlatformCell

* - fix merge

* - rollback compatibility changes

* - fix gallery and test cases

* - fix XAML Unit Tests

* - fix ui tests

Co-authored-by: Shane Neuville <[email protected]>
  • Loading branch information
rachelkang and PureWeen authored Feb 16, 2022
1 parent e168918 commit 3717ce0
Show file tree
Hide file tree
Showing 784 changed files with 5,799 additions and 5,684 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class BlazorWebViewHandler : ViewHandler<IBlazorWebView, BlazorAn
private AndroidWebKitWebViewManager? _webviewManager;
internal AndroidWebKitWebViewManager? WebviewManager => _webviewManager;

protected override BlazorAndroidWebView CreateNativeView()
protected override BlazorAndroidWebView CreatePlatformView()
{
var blazorAndroidWebView = new BlazorAndroidWebView(Context!)
{
Expand All @@ -48,9 +48,9 @@ protected override BlazorAndroidWebView CreateNativeView()
return blazorAndroidWebView;
}

protected override void DisconnectHandler(BlazorAndroidWebView nativeView)
protected override void DisconnectHandler(BlazorAndroidWebView platformView)
{
nativeView.StopLoading();
platformView.StopLoading();

if (_webviewManager != null)
{
Expand Down Expand Up @@ -81,7 +81,7 @@ private void StartWebViewCoreIfPossible()
{
return;
}
if (NativeView == null)
if (PlatformView == null)
{
throw new InvalidOperationException($"Can't start {nameof(BlazorWebView)} without native web view instance.");
}
Expand All @@ -93,7 +93,7 @@ private void StartWebViewCoreIfPossible()

var fileProvider = VirtualView.CreateFileProvider(contentRootDir);

_webviewManager = new AndroidWebKitWebViewManager(this, NativeView, Services!, ComponentsDispatcher, fileProvider, VirtualView.JSComponents, hostPageRelativePath);
_webviewManager = new AndroidWebKitWebViewManager(this, PlatformView, Services!, ComponentsDispatcher, fileProvider, VirtualView.JSComponents, hostPageRelativePath);

if (RootComponents != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.Components.WebView.Maui
{
public partial class BlazorWebViewHandler : ViewHandler<IBlazorWebView, object>
{
protected override object CreateNativeView() => throw new NotImplementedException();
protected override object CreatePlatformView() => throw new NotImplementedException();

public virtual IFileProvider CreateFileProvider(string contentRootDir) => throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public partial class BlazorWebViewHandler : ViewHandler<IBlazorWebView, WebView2
{
private WebView2WebViewManager? _webviewManager;

protected override WebView2Control CreateNativeView()
protected override WebView2Control CreatePlatformView()
{
return new WebView2Control();
}

protected override void DisconnectHandler(WebView2Control nativeView)
protected override void DisconnectHandler(WebView2Control platformView)
{
if (_webviewManager != null)
{
Expand Down Expand Up @@ -46,7 +46,7 @@ private void StartWebViewCoreIfPossible()
{
return;
}
if (NativeView == null)
if (PlatformView == null)
{
throw new InvalidOperationException($"Can't start {nameof(BlazorWebView)} without native web view instance.");
}
Expand All @@ -58,7 +58,7 @@ private void StartWebViewCoreIfPossible()

var fileProvider = VirtualView.CreateFileProvider(contentRootDir);

_webviewManager = new WinUIWebViewManager(NativeView, Services!, ComponentsDispatcher, fileProvider, VirtualView.JSComponents, hostPageRelativePath, contentRootDir);
_webviewManager = new WinUIWebViewManager(PlatformView, Services!, ComponentsDispatcher, fileProvider, VirtualView.JSComponents, hostPageRelativePath, contentRootDir);

if (RootComponents != null)
{
Expand Down
10 changes: 5 additions & 5 deletions src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public partial class BlazorWebViewHandler : ViewHandler<IBlazorWebView, WKWebVie
})();
";

protected override WKWebView CreateNativeView()
protected override WKWebView CreatePlatformView()
{
var config = new WKWebViewConfiguration();

Expand All @@ -73,9 +73,9 @@ private void MessageReceived(Uri uri, string message)
_webviewManager?.MessageReceivedInternal(uri, message);
}

protected override void DisconnectHandler(WKWebView nativeView)
protected override void DisconnectHandler(WKWebView platformView)
{
nativeView.StopLoading();
platformView.StopLoading();

if (_webviewManager != null)
{
Expand Down Expand Up @@ -103,7 +103,7 @@ private void StartWebViewCoreIfPossible()
{
return;
}
if (NativeView == null)
if (PlatformView == null)
{
throw new InvalidOperationException($"Can't start {nameof(BlazorWebView)} without native web view instance.");
}
Expand All @@ -115,7 +115,7 @@ private void StartWebViewCoreIfPossible()

var fileProvider = VirtualView.CreateFileProvider(contentRootDir);

_webviewManager = new IOSWebViewManager(this, NativeView, Services!, ComponentsDispatcher, fileProvider, VirtualView.JSComponents, hostPageRelativePath);
_webviewManager = new IOSWebViewManager(this, PlatformView, Services!, ComponentsDispatcher, fileProvider, VirtualView.JSComponents, hostPageRelativePath);

if (RootComponents != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ public async Task BasicBlazorComponentClick()
await InvokeOnMainThreadAsync(async () =>
{
var bwvHandler = CreateHandler<BlazorWebViewHandler>(bwv);
var nativeWebView = bwvHandler.NativeView;
await WebViewHelpers.WaitForWebViewReady(nativeWebView);
var platformWebView = bwvHandler.PlatformView;
await WebViewHelpers.WaitForWebViewReady(platformWebView);
// Click a button in a Razor component 3 times
await WebViewHelpers.WaitForControlDiv(bwvHandler.NativeView, controlValueToWaitFor: "0");
await WebViewHelpers.WaitForControlDiv(bwvHandler.PlatformView, controlValueToWaitFor: "0");
var c1 = await WebViewHelpers.ExecuteScriptAsync(bwvHandler.NativeView, "document.getElementById('incrementButton').click()");
var c1 = await WebViewHelpers.ExecuteScriptAsync(bwvHandler.PlatformView, "document.getElementById('incrementButton').click()");
await WebViewHelpers.WaitForControlDiv(bwvHandler.NativeView, controlValueToWaitFor: "1");
await WebViewHelpers.WaitForControlDiv(bwvHandler.PlatformView, controlValueToWaitFor: "1");
var c2 = await WebViewHelpers.ExecuteScriptAsync(bwvHandler.NativeView, "document.getElementById('incrementButton').click()");
var c2 = await WebViewHelpers.ExecuteScriptAsync(bwvHandler.PlatformView, "document.getElementById('incrementButton').click()");
await WebViewHelpers.WaitForControlDiv(bwvHandler.NativeView, controlValueToWaitFor: "2");
await WebViewHelpers.WaitForControlDiv(bwvHandler.PlatformView, controlValueToWaitFor: "2");
var c3 = await WebViewHelpers.ExecuteScriptAsync(bwvHandler.NativeView, "document.getElementById('incrementButton').click()");
var c3 = await WebViewHelpers.ExecuteScriptAsync(bwvHandler.PlatformView, "document.getElementById('incrementButton').click()");
await WebViewHelpers.WaitForControlDiv(bwvHandler.NativeView, controlValueToWaitFor: "3");
await WebViewHelpers.WaitForControlDiv(bwvHandler.PlatformView, controlValueToWaitFor: "3");
// And the counter value should increment from 0 to 3.
var actualFinalCounterValue = await WebViewHelpers.ExecuteScriptAsync(bwvHandler.NativeView, "document.getElementById('counterValue').innerText");
var actualFinalCounterValue = await WebViewHelpers.ExecuteScriptAsync(bwvHandler.PlatformView, "document.getElementById('counterValue').innerText");
actualFinalCounterValue = actualFinalCounterValue.Trim('\"'); // some platforms return quoted values, so we trim them
Assert.Equal("3", actualFinalCounterValue);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace Microsoft.Maui.DeviceTests
public partial class HandlerTestBase
{
protected bool GetIsAccessibilityElement(IViewHandler viewHandler) =>
GetSemanticNativeElement(viewHandler).ImportantForAccessibility == ImportantForAccessibility.Yes;
GetSemanticPlatformElement(viewHandler).ImportantForAccessibility == ImportantForAccessibility.Yes;


protected bool GetExcludedWithChildren(IViewHandler viewHandler) =>
GetSemanticNativeElement(viewHandler).ImportantForAccessibility == ImportantForAccessibility.NoHideDescendants;
GetSemanticPlatformElement(viewHandler).ImportantForAccessibility == ImportantForAccessibility.NoHideDescendants;

public View GetSemanticNativeElement(IViewHandler viewHandler)
public View GetSemanticPlatformElement(IViewHandler viewHandler)
{
if (viewHandler.NativeView is AndroidX.AppCompat.Widget.SearchView sv)
if (viewHandler.PlatformView is AndroidX.AppCompat.Widget.SearchView sv)
return sv.FindViewById(Resource.Id.search_button)!;

return (View)viewHandler.NativeView;
return (View)viewHandler.PlatformView;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.Maui.MauiBlazorWebView.DeviceTests
public partial class HandlerTestBase
{
protected bool GetIsAccessibilityElement(IViewHandler viewHandler) =>
((AccessibilityView)((DependencyObject)viewHandler.NativeView).GetValue(NativeAutomationProperties.AccessibilityViewProperty))
((AccessibilityView)((DependencyObject)viewHandler.PlatformView).GetValue(NativeAutomationProperties.AccessibilityViewProperty))
== AccessibilityView.Content;
}
}
2 changes: 1 addition & 1 deletion src/BlazorWebView/tests/MauiDeviceTests/HandlerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected THandler CreateHandler<THandler>(IView view)
view.Handler = handler;

view.Arrange(new Rectangle(0, 0, view.Width, view.Height));
handler.NativeArrange(view.Frame);
handler.PlatformArrange(view.Frame);

return handler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public partial class HandlerTestBase
{
protected bool GetIsAccessibilityElement(IViewHandler viewHandler)
{
var nativeView = ((UIView)viewHandler.NativeView);
return nativeView.IsAccessibilityElement;
var platformView = ((UIView)viewHandler.PlatformView);
return platformView.IsAccessibilityElement;
}

protected bool GetExcludedWithChildren(IViewHandler viewHandler)
{
var nativeView = ((UIView)viewHandler.NativeView);
return nativeView.AccessibilityElementsHidden;
var platformView = ((UIView)viewHandler.PlatformView);
return platformView.AccessibilityElementsHidden;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ namespace Microsoft.Maui.MauiBlazorWebView.DeviceTests
#if !WINDOWS && !ANDROID && !IOS
public static class WebViewHelpers
{
public static Task WaitForWebViewReady(object nativeWebView)
public static Task WaitForWebViewReady(object platformWebView)
{
return Task.CompletedTask;
}

public static Task WaitForControlDiv(object nativeWebView, string controlValueToWaitFor)
public static Task WaitForControlDiv(object platformWebView, string controlValueToWaitFor)
{
return Task.CompletedTask;
}

public static Task<string> ExecuteScriptAsync(object nativeWebView, string script)
public static Task<string> ExecuteScriptAsync(object platformWebView, string script)
{
return Task.FromResult<string>(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls.Compatibility.ControlGallery
{
public class PlatformBindingGalleryPage : ContentPage
{
public new StackLayout Layout { get; set; }
public bool PlatformControlsAdded { get; set; }

NestedPlatformViewModel ViewModel { get; set; }

public const string ReadyForPlatformBindingsMessage = "ReadyForPlatformBindings";

protected override void OnAppearing()
{
base.OnAppearing();
MessagingCenter.Send(this, ReadyForPlatformBindingsMessage);
}

public PlatformBindingGalleryPage()
{

var vm = new NestedPlatformViewModel();
vm.FormsLabel = "Forms Label Binding";
vm.PlatformLabel = "Native Label Binding";
vm.PlatformLabelColor = Colors.Red;
vm.Age = 45;

Layout = new StackLayout { Padding = 20, VerticalOptions = LayoutOptions.FillAndExpand };

var buttonNav = new Button { Text = "New Page" };
buttonNav.Clicked += (object sender, EventArgs e) =>
{
App.Current.MainPage = new ContentPage { Content = new Label { Text = "New page" } };
};

var button = new Button { Text = "Change BindingContext " };
button.Clicked += (object sender, EventArgs e) =>
{
vm = new NestedPlatformViewModel();
vm.FormsLabel = "Forms Label Binding Changed";
vm.PlatformLabel = "Native Label Binding Changed";
vm.PlatformLabelColor = Colors.Pink;
vm.Age = 10;
BindingContext = ViewModel = vm;
;
};

var boxView = new BoxView { HeightRequest = 50 };
boxView.SetBinding(BoxView.BackgroundColorProperty, "PlatformLabelColor");

var label = new Label();
label.SetBinding(Label.TextProperty, "FormsLabel");
var labelAge = new Label();
labelAge.SetBinding(Label.TextProperty, nameof(vm.Age));

Layout.Children.Add(buttonNav);
Layout.Children.Add(label);
Layout.Children.Add(boxView);
Layout.Children.Add(button);
Layout.Children.Add(labelAge);

BindingContext = ViewModel = vm;
;

Content = new ScrollView { Content = Layout };
}
}


[Preserve(AllMembers = true)]
public class NestedPlatformViewModel : ViewModelBase
{
string _formsLabel;
public string FormsLabel
{
get { return _formsLabel; }
set { if (_formsLabel == value) return; _formsLabel = value; OnPropertyChanged(); }
}

string _platformLabel;
public string PlatformLabel
{
get { return _platformLabel; }
set { if (_platformLabel == value) return; _platformLabel = value; OnPropertyChanged(); }
}

Color _platformLabelColor;
public Color PlatformLabelColor
{
get { return _platformLabelColor; }
set { if (_platformLabelColor == value) return; _platformLabelColor = value; OnPropertyChanged(); }
}

int _age;
public int Age
{
get { return _age; }
set { if (_age == value) return; _age = value; OnPropertyChanged(); }
}

bool _selected;
public bool Selected
{
get { return _selected; }
set { if (_selected == value) return; _selected = value; OnPropertyChanged(); }
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls.Compatibility.ControlGallery
{
public interface IPlatformColorService
{
Color GetConvertedColor(bool shouldCrash);
}
}
4 changes: 2 additions & 2 deletions src/Compatibility/ControlGallery/src/iOS/CustomRenderers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Bugzilla21177.C
{
SectionInset = new UIEdgeInsets(20, 20, 20, 20),
ScrollDirection = UICollectionViewScrollDirection.Vertical,
MinimumInteritemSpacing = 5, // minimum spacing between cells 
MinimumLineSpacing = 5 // minimum spacing between rows if ScrollDirection is Vertical or between columns if Horizontal 
MinimumInteritemSpacing = 5, // minimum spacing between cells
MinimumLineSpacing = 5 // minimum spacing between rows if ScrollDirection is Vertical or between columns if Horizontal
};
_controller = new CollectionViewController(flowLayout, ItemSelected);
SetNativeControl(_controller.CollectionView);
Expand Down
2 changes: 1 addition & 1 deletion src/Compatibility/Core/src/Android/AppCompat/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ internal static IVisualElementRenderer CreateRenderer(
}
else if (handler is IVisualElementRenderer ver)
renderer = ver;
else if (handler is INativeViewHandler vh)
else if (handler is IPlatformViewHandler vh)
{
renderer = new HandlerToRendererShim(vh);
element.Handler = handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void UpdateIndicatorCount()
{
RemoveViewAt(ChildCount - 1);
}
IndicatorView.NativeSizeChanged();
IndicatorView.PlatformSizeChanged();
}

void ResetIndicators()
Expand Down
Loading

0 comments on commit 3717ce0

Please sign in to comment.