Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

[C] new OnPlatform mechanism #658

Merged
merged 3 commits into from
Jan 12, 2017
Merged
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 @@ -19,11 +19,18 @@ public partial class Bugzilla22229 : TabbedPage
public Bugzilla22229()
{
InitializeComponent();
_prefix = Device.OnPlatform(
iOS: "Images/",
Android: "",
WinPhone: "Assets/"
);
switch (Device.RuntimePlatform) {
case Device.iOS:
_prefix = "Images/";
break;
case Device.Android:
_prefix = "";
break;
case Device.Windows:
case Device.WinPhone:
_prefix = "Assets/";
break;
}
InitializeActionBar();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ protected override void Init ()

var listView = new ListView {
IsGroupingEnabled = true,
GroupDisplayBinding = new Binding ("GroupName"),
GroupShortNameBinding = new Binding ("GroupName"),
HasUnevenRows = Device.OnPlatform (Android: true, WinPhone: false, iOS: false),
GroupDisplayBinding = new Binding("GroupName"),
GroupShortNameBinding = new Binding("GroupName"),
HasUnevenRows = Device.RuntimePlatform == Device.Android,

ItemTemplate = itemTemplate,
GroupHeaderTemplate = groupHeaderTemplate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Bugzilla34632 : TestMasterDetailPage
{
protected override void Init ()
{
if (Device.OS == TargetPlatform.Windows)
if (Device.RuntimePlatform == Device.Windows)
MasterBehavior = MasterBehavior.Split;
else
MasterBehavior = MasterBehavior.SplitOnLandscape;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ protected override void Init()

if (!Application.Current.Resources.ContainsKey("SomeSmallImage"))
{
var smallImage = new OnPlatform<ImageSource> {
Android = ImageSource.FromFile("coffee.png"),
WinPhone = ImageSource.FromFile("bank.png"),
iOS = ImageSource.FromFile("coffee.png")
};
ImageSource smallImage;
switch (Device.RuntimePlatform) {
default:
smallImage = "coffee.png";
break;
case Device.WinPhone:
case Device.Windows:
smallImage = "bank.png";
break;
}

Application.Current.Resources.Add("SomeSmallImage", smallImage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ static ContentPage TimePickerPage()

return new ContentPage {
Title = "TimePicker",
Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, Device.OnPlatform(00, 0, 0)),
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(0, 20, 0, 0) : new Thickness(0),
Content = new StackLayout {
VerticalOptions = LayoutOptions.Fill,
HorizontalOptions = LayoutOptions.Fill,
Expand Down Expand Up @@ -389,7 +389,7 @@ static ContentPage DatePickerPage()

return new ContentPage {
Title = "DatePicker",
Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, Device.OnPlatform(00, 0, 0)),
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(0, 20, 0, 0) : new Thickness(0),
Content = new StackLayout {
VerticalOptions = LayoutOptions.Fill,
HorizontalOptions = LayoutOptions.Fill,
Expand Down Expand Up @@ -457,7 +457,7 @@ static ContentPage PickerPage()

return new ContentPage {
Title = "Picker",
Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, Device.OnPlatform(00, 0, 0)),
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(0, 20, 0, 0) : new Thickness(0),
Content = new StackLayout {
VerticalOptions = LayoutOptions.Fill,
HorizontalOptions = LayoutOptions.Fill,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override void Init()

Grid fakeUri = CreateTest(() => image.Source = ImageSource.FromUri(new Uri("http://not.real")),
"Non-existent URI",
Device.OS == TargetPlatform.Windows && Device.Idiom == TargetIdiom.Phone
Device.RuntimePlatform == Device.Windows && Device.Idiom == TargetIdiom.Phone
? "Clicking this button should display an alert dialog. The error message should include the text 'NotFound'."
: "Clicking this button should display an alert dialog. The error message should include the text 'the server name or address could not be resolved'.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Issue1075 ()
};

// Accomodate iPhone status bar.
Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 0);
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(10, 20, 10, 0) : new Thickness(10, 0);

// Build the page.
Content = new StackLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public Issue1461Page (MasterBehavior state, bool? initState)
Master = new ContentPage {
Title = string.Format ("Master sample for {0}", state),
Icon = "bank.png",
Padding = Device.OnPlatform (new Thickness (5, 60, 5, 5), 5, 5),
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(5, 60, 5, 5) : new Thickness(5),
Content =
new StackLayout { Children = {
new Label {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public SwitchDemoPage()
};

// Accomodate iPhone status bar.
Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(10, 20, 10, 5) : new Thickness(10, 0, 10, 5);

// Build the page.
Content = new StackLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Issue194 ()
Title = "Page 9"
};

Device.OnPlatform (iOS: () => {
if (Device.RuntimePlatform == Device.iOS) {
// Create an overflow amount of tabs depending on device
if (Device.Idiom == TargetIdiom.Tablet) {
Children.Add (pageOne);
Expand All @@ -67,7 +67,7 @@ public Issue194 ()
Children.Add (pageFive);
Children.Add (pageSix);
}
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected override void Init ()
listView.ScrollTo (person, ScrollToPosition.End, true);
};

Padding = new Thickness (10, Device.OnPlatform (20, 0, 0), 10, 5);
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(10, 20, 10, 5) : new Thickness(10, 0, 10, 5);

Content = new StackLayout {
Orientation = StackOrientation.Vertical,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public CustomWebView (WebViewViewModel webViewViewModel) : this ()

static void WebView_OnNavigating (object sender, WebNavigatingEventArgs e)
{
Debug.WriteLine ("OS: " + Device.OS + " Current Url: " + GetSourceUrl (((WebView)sender).Source) + "Destination Url: " + e.Url + " " + DateTime.Now);
Debug.WriteLine ("OS: " + Device.RuntimePlatform + " Current Url: " + GetSourceUrl (((WebView)sender).Source) + "Destination Url: " + e.Url + " " + DateTime.Now);

if (e.Url.IsValidAbsoluteUrl ()) {
var destinationUri = new Uri (e.Url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public Issue2597()
};

// Accomodate iPhone status bar.
Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10,
5);
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(10, 20, 10, 5) : new Thickness(10, 0, 10, 5);

// Build the page.
Content = new StackLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,10 @@ public AddPatientView ()
Forms.Constraint.RelativeToParent ((parent) =>
parent.Height));

rl.Children.Add (addFrame,
Forms.Constraint.RelativeToParent ((parent) =>
(parent.Width * .25) / 2),
Forms.Constraint.Constant (Device.OnPlatform (60, 40, 40)),
Forms.Constraint.RelativeToParent ((parent) =>
parent.Width * .75));
rl.Children.Add(addFrame,
Forms.Constraint.RelativeToParent((parent) => (parent.Width * .25) / 2),
Forms.Constraint.Constant(Device.RuntimePlatform == Device.iOS ? 60 : 40),
Forms.Constraint.RelativeToParent((parent) => parent.Width * .75));

Content = rl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public SliderMenuPage ()
Children = { logoImg }
};

var paddingTop = Device.OnPlatform (40, 2, 2);
var paddingTop = Device.RuntimePlatform == Device.iOS ? 40 : 2;
Content = new StackLayout {
Spacing = 0,
BackgroundColor = Color.FromHex ("1e1e1e"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ public NativeListPage ()

// The root page of your application
Content = new StackLayout {
Padding = new Thickness (0, Device.OnPlatform(20,0,0), 0, 0),
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(0, 20, 0, 0) : new Thickness(0),
Children = {
new Label {
#pragma warning disable 618
XAlign = TextAlignment.Center,
#pragma warning restore 618
Text = Device.OnPlatform("Custom renderer UITableView","Custom renderer ListView","Custom renderer todo")
Text = Device.RuntimePlatform == Device.iOS ? "Custom renderer UITableView" : Device.RuntimePlatform == Device.Android ? "Custom renderer ListView" : "Custom renderer todo"
},
fasterListView
fasterListView
}
};
}
Expand Down Expand Up @@ -143,7 +143,7 @@ public XamarinFormsPage ()
};

Content = new StackLayout {
Padding = new Thickness (5, Device.OnPlatform(20,0,0), 5, 0),
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(5, 20, 5, 0) : new Thickness(5,0),
Children = {
new Label {
#pragma warning disable 618
Expand Down Expand Up @@ -185,7 +185,7 @@ public XamarinFormsNativeCellPage ()
};

Content = new StackLayout {
Padding = new Thickness (0, Device.OnPlatform(20,0,0), 0, 0),
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(0, 20, 0, 0) : new Thickness(0),
Children = {
new Label {
#pragma warning disable 618
Expand Down Expand Up @@ -250,7 +250,7 @@ public DetailPage (object detail)
b.Clicked += (sender, e) => Navigation.PopModalAsync();

Content = new StackLayout {
Padding = new Thickness (0, Device.OnPlatform(20,0,0), 0, 0),
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(0, 20, 0, 0) : new Thickness(0),
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Children = {
Expand Down Expand Up @@ -289,13 +289,13 @@ public NativeListViewPage2 ()

// The root page of your application
Content = new StackLayout {
Padding = new Thickness (0, Device.OnPlatform(20,0,0), 0, 0),
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(0, 20, 0, 0) : new Thickness(0),
Children = {
new Label {
#pragma warning disable 618
XAlign = TextAlignment.Center,
#pragma warning restore 618
Text = Device.OnPlatform("Custom UITableView+UICell","Custom ListView+Cell","Custom renderer todo")
Text = Device.RuntimePlatform == Device.iOS ? "Custom UITableView+UICell" : Device.RuntimePlatform == Device.Android ? "Custom ListView+Cell" : "Custom renderer todo"
},
nativeListView2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void Init ()
Debug.WriteLine ("Date changed");
};

Padding = new Thickness (10, Device.OnPlatform (20, 0, 0), 10, 5);
Padding = Device.RuntimePlatform == Device.iOS ? new Thickness(10, 20, 10, 5) : new Thickness(10, 0, 10, 5);

layout = new AbsoluteLayout {
VerticalOptions = LayoutOptions.FillAndExpand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ public CannotScrollRepro ()

layout.Children.Add (label);

layout.Children.Add (new ScrollView {
layout.Children.Add(new ScrollView {
BackgroundColor = Color.Aqua,
Orientation = ScrollOrientation.Horizontal,
HeightRequest = Device.OnPlatform (44, 44, 80),
HeightRequest = Device.RuntimePlatform == Device.Windows || Device.RuntimePlatform == Device.WinPhone ? 80 : 44,
Content = buttonStack
});

Expand Down
7 changes: 2 additions & 5 deletions Xamarin.Forms.Controls/GalleryPages/AbsoluteLayoutGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ public class AbsoluteLayoutGallery : ContentPage
{
public AbsoluteLayoutGallery ()
{
Device.OnPlatform (iOS: () => {
if (Device.Idiom == TargetIdiom.Tablet) {
Padding = new Thickness (0, 0, 0, 60);
}
});
if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet)
Padding = new Thickness(0, 0, 0, 60);

BindingContext = new AbsolutePositioningExplorationViewModel ();
var absLayout = new AbsoluteLayout {
Expand Down
15 changes: 14 additions & 1 deletion Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,21 @@ public ButtonGallery ()
var click = new Button { Text = "Click Button" };
var rotate = new Button { Text = "Rotate Button" };
var transparent = new Button { Text = "Transparent Button" };
string fontName;
switch (Device.RuntimePlatform) {
default:
case Device.iOS:
fontName = "Georgia";
break;
case Device.Android:
fontName = "sans-serif-light";
break;
case Device.WinPhone:
case Device.Windows:
fontName = "Comic Sans MS";
break;
}

var fontName = Device.OnPlatform ("Georgia", "sans-serif-light", "Comic Sans MS");
var font = Font.OfSize (fontName, NamedSize.Medium);

var themedButton = new Button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ public EntryCellListPage ()
{
Title = "EntryCell List Gallery - Legacy";

Device.OnPlatform (iOS: () => {
if (Device.Idiom == TargetIdiom.Tablet) {
Padding = new Thickness (0, 0, 0, 60);
}
});
if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet)
Padding = new Thickness(0, 0, 0, 60);

var dataTemplate = new DataTemplate (typeof(EntryCell));
dataTemplate.SetBinding (EntryCell.LabelProperty, new Binding ("Label"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ public EntryCellTablePage ()
{
Title = "EntryCell Table Gallery - Legacy";

Device.OnPlatform (iOS: () => {
if (Device.Idiom == TargetIdiom.Tablet) {
Padding = new Thickness (0, 0, 0, 60);
}
});
if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet)
Padding = new Thickness(0, 0, 0, 60);

int timesEntered = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ public ImageCellListPage ()
{
Title = "ImageCell List Gallery - Legacy";

Device.OnPlatform (iOS: () => {
if (Device.Idiom == TargetIdiom.Tablet) {
Padding = new Thickness (0, 0, 0, 60);
}
});
if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet)
Padding = new Thickness(0, 0, 0, 60);

var dataTemplate = new DataTemplate (typeof (ImageCell));
var stringToImageSourceConverter = new GenericValueConverter (
Expand Down Expand Up @@ -73,11 +70,8 @@ public class UrlImageCellListPage : ContentPage
{
public UrlImageCellListPage()
{
Device.OnPlatform (iOS: () => {
if (Device.Idiom == TargetIdiom.Tablet) {
Padding = new Thickness (0, 0, 0, 60);
}
});
if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet)
Padding = new Thickness(0, 0, 0, 60);

var dataTemplate = new DataTemplate (typeof (ImageCell));
var stringToImageSourceConverter = new GenericValueConverter (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ public ImageCellTablePage ()
{
Title = "ImageCell Table Gallery - Legacy";

Device.OnPlatform (iOS: () => {
if (Device.Idiom == TargetIdiom.Tablet) {
Padding = new Thickness (0, 0, 0, 60);
}
});
if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet)
Padding = new Thickness(0, 0, 0, 60);

var tableSection = new TableSection ("Section One") {
new ImageCell { Text = "Text 1", ImageSource = new FileImageSource { File = "crimson.jpg" } },
Expand Down
Loading