Skip to content

Commit

Permalink
feature: Add support for Xamarin TV.OS (reactiveui#1706)
Browse files Browse the repository at this point in the history
  • Loading branch information
glennawatson authored Aug 14, 2018
1 parent 0a75342 commit 2a067c0
Show file tree
Hide file tree
Showing 33 changed files with 182 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ src/ReactiveUI/Platforms/net461/* @reactiveui/wpf-team @reactiveui/winf
src/ReactiveUI/Platforms/netcoreapp2.0/* @reactiveui/dotnetcore-team @reactiveui/webassembly-team
src/ReactiveUI/Platforms/uap10.0.16299/* @reactiveui/uwp-team
src/ReactiveUI/Platforms/tizen/* @reactiveui/tizen-team
src/ReactiveUI/Platforms/tvos/* @reactiveui/tvos-team
src/ReactiveUI/Platforms/windows-common/* @reactiveui/wpf-team @reactiveui/winforms-team @reactiveui/uwp-team
src/ReactiveUI/Platforms/xamarin-common/* @reactiveui/xamarin-forms-team

Expand Down
2 changes: 2 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ Task("GenerateEvents")
generate("wpf", "src/ReactiveUI.Events.WPF/");
generate("xamforms", "src/ReactiveUI.Events.XamForms/");
generate("winforms", "src/ReactiveUI.Events.Winforms/");
generate("essentials", "src/ReactiveUI.Events/");
generate("tvos", "src/ReactiveUI.Events/");
});

Task("BuildReactiveUI")
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Authors>.NET Foundation and Contributors</Authors>
<Owners>xpaulbettsx;ghuntley</Owners>
<Product>ReactiveUI ($(TargetFramework))</Product>
<PackageTags>mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;xamarin;android;ios;mac;forms;monodroid;monotouch;xamarin.android;xamarin.ios;xamarin.forms;xamarin.mac;wpf;net;netstandard;net461;uwp;tizen</PackageTags>
<PackageTags>mvvm;reactiveui;rx;reactive extensions;observable;LINQ;events;frp;xamarin;android;ios;mac;forms;monodroid;monotouch;xamarin.android;xamarin.ios;xamarin.forms;xamarin.mac;xamarin.tvos;wpf;net;netstandard;net461;uwp;tizen</PackageTags>
<PackageReleaseNotes>https://reactiveui.net/blog/</PackageReleaseNotes>

<NoWarn>$(NoWarn);1591;1701;1702;1705</NoWarn>
Expand Down
3 changes: 3 additions & 0 deletions src/Directory.build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'Xamarin.Mac20'">
<DefineConstants>$(DefineConstants);MONO;COCOA</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'Xamarin.TVOS10'">
<DefineConstants>$(DefineConstants);MONO;UIKIT;COCOA;TVOS10</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'MonoAndroid80'">
<DefineConstants>$(DefineConstants);MONO;ANDROID</DefineConstants>
Expand Down
3 changes: 2 additions & 1 deletion src/EventBuilder/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum AutoPlatform
XamForms,
UWP,
Winforms,
TVOS,
Essentials
}

Expand All @@ -29,7 +30,7 @@ public class CommandLineOptions

[Option('p', "platform", Required = true,
HelpText =
"Platform to automatically generate. Possible options include: NONE, ANDROID, IOS, WPF, MAC, TIZEN, UWP, XAMFORMS, WINFORMS"
"Platform to automatically generate. Possible options include: NONE, ANDROID, IOS, WPF, MAC, TIZEN, UWP, XAMFORMS, WINFORMS, TVOS"
)]
public AutoPlatform Platform { get; set; }

Expand Down
35 changes: 35 additions & 0 deletions src/EventBuilder/Platforms/tvOS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.IO;
using System.Linq;

namespace EventBuilder.Platforms
{
// ReSharper disable once InconsistentNaming
public class TVOS : BasePlatform
{
public override AutoPlatform Platform => AutoPlatform.TVOS;

public TVOS(string referenceAssembliesLocation)
{
if (PlatformHelper.IsRunningOnMono()) {
var assembly =
@"/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.TVOS10/Xamarin.TVOS10.dll";
Assemblies.Add(assembly);

CecilSearchDirectories.Add(Path.GetDirectoryName(assembly));
} else {
var assemblies =
Directory.GetFiles(Path.Combine(referenceAssembliesLocation, "Xamarin.TVOS"),
"Xamarin.TVOS.dll", SearchOption.AllDirectories);

var latestVersion = assemblies.Last();
Assemblies.Add(latestVersion);

CecilSearchDirectories.Add(Path.GetDirectoryName(latestVersion));
}
}
}
}
6 changes: 5 additions & 1 deletion src/EventBuilder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ private static void Main(string[] args)
platform = new Mac(_referenceAssembliesLocation);
break;

case AutoPlatform.WPF:
case AutoPlatform.TVOS:
platform = new TVOS(_referenceAssembliesLocation);
break;

case AutoPlatform.WPF:
platform = new WPF();
break;

Expand Down
6 changes: 5 additions & 1 deletion src/ReactiveUI.Events/ReactiveUI.Events.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFrameworks>uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;MonoAndroid80;tizen40</TargetFrameworks>
<TargetFrameworks>uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;MonoAndroid80;tizen40</TargetFrameworks>
<AssemblyName>ReactiveUI.Events</AssemblyName>
<RootNamespace>ReactiveUI.Events</RootNamespace>
<Description>Provides Observable-based events API for common UI controls/eventhandlers. The contents of this package is automatically generated, please target pull-requests to the code generator.</Description>
Expand Down Expand Up @@ -43,4 +43,8 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'Xamarin.Mac20' ">
<Reference Include="netstandard" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'Xamarin.TVOS10' ">
<Reference Include="netstandard" />
</ItemGroup>
</Project>
6 changes: 5 additions & 1 deletion src/ReactiveUI.Fody.Helpers/ReactiveUI.Fody.Helpers.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461;uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;MonoAndroid80;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net461;uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;MonoAndroid80;netcoreapp2.0</TargetFrameworks>
<AssemblyName>ReactiveUI.Fody.Helpers</AssemblyName>
<RootNamespace>ReactiveUI.Fody.Helpers</RootNamespace>
<Description>Fody extension to generate RaisePropertyChange notifications for properties and ObservableAsPropertyHelper properties.</Description>
Expand Down Expand Up @@ -28,6 +28,10 @@
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.TVOS10'))">
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.Mac'))">
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveUI.Testing/ReactiveUI.Testing.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp2.0;net461;uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;MonoAndroid80</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp2.0;net461;uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;MonoAndroid80</TargetFrameworks>
<AssemblyName>ReactiveUI.Testing</AssemblyName>
<RootNamespace>ReactiveUI.Testing</RootNamespace>
<Description>A library to aid in writing unit tests for ReactiveUI projects</Description>
Expand Down
4 changes: 2 additions & 2 deletions src/ReactiveUI/Platforms/apple-common/PlatformOperations.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand All @@ -11,7 +11,7 @@ public class PlatformOperations : IPlatformOperations
{
public string GetOrientation()
{
#if UIKIT
#if UIKIT && !TVOS10
return UIKit.UIDevice.CurrentDevice.Orientation.ToString();
#else
return null;
Expand Down
57 changes: 57 additions & 0 deletions src/ReactiveUI/Platforms/tvos/LinkerOverrides.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using UIKit;

namespace ReactiveUI.Cocoa
{
/// <summary>
/// This class exists to force the MT linker to include properties called by RxUI via reflection
/// </summary>
[Preserve(AllMembers = true)]
class LinkerOverrides
{
public void KeepMe()
{
// UIButon
var btn = new UIButton();
var title = btn.Title(UIControlState.Disabled);
btn.SetTitle("foo", UIControlState.Disabled);
btn.TitleLabel.Text = btn.TitleLabel.Text;

// UITextView
var tv = new UITextView();
tv.Text = tv.Text;

// UITextField
var tf = new UITextField();
tv.Text = tf.Text;

// var UIImageView
var iv = new UIImageView();
iv.Image = iv.Image;

// UI Label
var lbl = new UILabel();
lbl.Text = lbl.Text;

// UI Control
var ctl = new UIControl();
ctl.Enabled = ctl.Enabled;
ctl.Selected = ctl.Selected;

EventHandler eh = (s, e) => { };
ctl.TouchUpInside += eh;
ctl.TouchUpInside -= eh;

// UIBarButtonItem
var bbi = new UIBarButtonItem();
bbi.Clicked += eh;
bbi.Clicked -= eh;

eh.Invoke(null, null);
}
}
}
22 changes: 22 additions & 0 deletions src/ReactiveUI/Platforms/tvos/UIKitCommandBinders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Reflection;
using UIKit;

namespace ReactiveUI
{
public class UIKitCommandBinders : FlexibleCommandBinder
{
public static Lazy<UIKitCommandBinders> Instance = new Lazy<UIKitCommandBinders>();

public UIKitCommandBinders()
{
Register(typeof(UIControl), 9, (cmd, t, cp) => ForTargetAction(cmd, t, cp, typeof(UIControl).GetRuntimeProperty("Enabled")));
Register(typeof(UIBarButtonItem), 10, (cmd, t, cp) => ForEvent(cmd, t, cp, "Clicked", typeof(UIBarButtonItem).GetRuntimeProperty("Enabled")));
}
}
}

31 changes: 31 additions & 0 deletions src/ReactiveUI/Platforms/tvos/UIKitObservableForProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using UIKit;

namespace ReactiveUI
{
[Preserve]
public class UIKitObservableForProperty : ObservableForPropertyBase
{
public static Lazy<UIKitObservableForProperty> Instance = new Lazy<UIKitObservableForProperty>();

public UIKitObservableForProperty()
{
Register(typeof(UIControl), "Value", 20, (s, p) => ObservableFromUIControlEvent(s, p, UIControlEvent.ValueChanged));
Register(typeof(UITextField), "Text", 30, (s, p) => ObservableFromNotification(s, p, UITextField.TextFieldTextDidChangeNotification));
Register(typeof(UITextView), "Text", 30, (s, p) => ObservableFromNotification(s, p, UITextView.TextDidChangeNotification));
Register(typeof(UISegmentedControl), "SelectedSegment", 30, (s, p) => ObservableFromUIControlEvent(s, p, UIControlEvent.ValueChanged));
Register(typeof(UISegmentedControl), "SelectedSegment", 30, (s, p) => ObservableFromUIControlEvent(s, p, UIControlEvent.ValueChanged));

// Warning: This will stomp the Control's delegate
Register(typeof(UITabBar), "SelectedItem", 30, (s, p) => ObservableFromEvent(s, p, "ItemSelected"));

// Warning: This will stomp the Control's delegate
Register(typeof(UISearchBar), "Text", 30, (s, p) => ObservableFromEvent(s, p, "TextChanged"));
}
}
}

11 changes: 10 additions & 1 deletion src/ReactiveUI/ReactiveUI.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461;uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;MonoAndroid80;netcoreapp2.0;tizen40</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net461;uap10.0.16299;Xamarin.iOS10;Xamarin.Mac20;Xamarin.TVOS10;MonoAndroid80;netcoreapp2.0;tizen40</TargetFrameworks>
<AssemblyName>ReactiveUI</AssemblyName>
<RootNamespace>ReactiveUI</RootNamespace>
<Description>A MVVM framework that integrates with the Reactive Extensions for .NET to create elegant, testable User Interfaces that run on any mobile or desktop platform. Supports Xamarin.iOS, Xamarin.Android, Xamarin.Mac, Xamarin Forms, WPF, Windows Forms, Windows Phone 8.1, Windows Store and Universal Windows Platform (UWP).</Description>
Expand Down Expand Up @@ -39,6 +39,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'Xamarin.iOS10' ">
<Compile Include="Platforms\apple-common\**\*.cs" />
<Compile Include="Platforms\ios\**\*.cs" />
<Compile Include="Platforms\uikit-common\**\*.cs" />
<Compile Include="Platforms\xamarin-common\**\*.cs" />
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>
Expand All @@ -51,6 +52,14 @@
<Reference Include="netstandard" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'Xamarin.TVOS10' ">
<Compile Include="Platforms\apple-common\**\*.cs" />
<Compile Include="Platforms\tvos\**\*.cs" />
<Compile Include="Platforms\uikit-common\**\*.cs" />
<Compile Include="Platforms\xamarin-common\**\*.cs" />
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'MonoAndroid80' ">
<Compile Include="Platforms\android\**\*.cs" />
<Compile Include="Platforms\xamarin-common\**\*.cs" />
Expand Down

0 comments on commit 2a067c0

Please sign in to comment.