Skip to content

Commit

Permalink
Merge pull request #79 from AvaloniaUI/features/ios
Browse files Browse the repository at this point in the history
XPlat template supports iOS and Android
  • Loading branch information
danwalmsley authored Mar 12, 2022
2 parents 1a21147 + e5ffcb0 commit 15ef231
Show file tree
Hide file tree
Showing 32 changed files with 333 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Avalonia.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageType>Template</PackageType>
<PackageVersion>0.10.12.1</PackageVersion>
<PackageVersion>0.10.13</PackageVersion>
<PackageId>Avalonia.Templates</PackageId>
<Title>Avalonia Templates</Title>
<Description>Templates for creating Avalonia applications and libraries.</Description>
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pool:
vmImage: 'windows-2019'
vmImage: 'macos-latest'
steps:
- task: UseDotNet@2
displayName: 'Use .NET 6.0.x SDK'
Expand All @@ -20,7 +20,7 @@ steps:
- task: CmdLine@2
displayName: 'Install WASM workload'
inputs:
script: 'dotnet workload install wasm-tools'
script: 'dotnet workload install --no-cache --disable-parallel ios android wasm-tools --skip-manifest-update --source "https://api.nuget.org/v3/index.json"'
- task: PowerShell@2
displayName: 'Run Tests'
inputs:
Expand Down
2 changes: 1 addition & 1 deletion nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

<configuration>
<packageSources>
<add key="AvaloniaCI" value="https://www.myget.org/F/avalonia-ci/api/v2" />
<add key="AvaloniaCI" value="https://nuget.avaloniaui.net/repository/avalonia-nightly/index.json" />
</packageSources>
</configuration>
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ To create a new Cross-Platform application in its own subdirectory, run:
dotnet new avalonia.xplat
```
**Note:**
This type of template allows you to create a program that will work on Desktop and on Web via WASM (preview).
This type of template allows you to create an application that will work on Desktop, Browser (preview) and Mobile (iOS & Android) (preview).

# Creating a new Application

Expand Down
8 changes: 4 additions & 4 deletions templates/csharp/app-mvvm/AvaloniaAppTemplate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
<TrimmableAssembly Include="Avalonia.Themes.Default" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.12" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.12" />
<PackageReference Include="Avalonia" Version="0.10.13" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.13" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.12" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.12" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.13" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.13" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions templates/csharp/app/AvaloniaAppTemplate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<TrimmableAssembly Include="Avalonia.Themes.Default" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.12" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.12" />
<PackageReference Include="Avalonia" Version="0.10.13" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.13" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.12" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.13" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-android</TargetFramework>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<ApplicationId>com.CompanyName.AvaloniaTest</ApplicationId>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<AndroidPackageFormat>apk</AndroidPackageFormat>
<MSBuildEnableWorkloadResolver>true</MSBuildEnableWorkloadResolver>
<!--<RunAOTCompilation>true</RunAOTCompilation>
<AndroidEnableProfiledAot>true</AndroidEnableProfiledAot>-->
</PropertyGroup>
<ItemGroup>
<AndroidResource Include="Icon.png">
<Link>Resources\drawable\Icon.png</Link>
</AndroidResource>
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release' and '$(TF_BUILD)' == ''">
<RunAOTCompilation>True</RunAOTCompilation>
<EnableLLVM>True</EnableLLVM>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
<RunAOTCompilation>False</RunAOTCompilation>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.3.1.3" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.ViewModel" Version="2.3.1.3" />
<PackageReference Include="Avalonia.Android" Version="$(AvaloniaVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AvaloniaTest\AvaloniaTest.csproj" />
</ItemGroup>
</Project>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions templates/csharp/xplat/AvaloniaTest.Android/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Android.App;
using Android.Content.PM;
using Avalonia.Android;
using Avalonia;

namespace AvaloniaTest.Android
{
[Activity(Label = "AvaloniaTest.Android", Theme = "@style/MyTheme.NoActionBar", Icon = "@drawable/icon", LaunchMode = LaunchMode.SingleInstance, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
public class MainActivity : AvaloniaActivity<App>
{
protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
{
return base.CustomizeAppBuilder(builder);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="AvaloniaTest" android:icon="@drawable/Icon" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item>
<color android:color="@color/splash_background"/>
</item>

<item android:drawable="@drawable/icon"
android:width="120dp"
android:height="120dp"
android:gravity="center" />

</layer-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="splash_background">#FFFFFF</color>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<resources>

<style name="MyTheme">
</style>

<style name="MyTheme.NoActionBar" parent="@style/Theme.AppCompat.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>

<style name="MyTheme.Splash" parent ="MyTheme.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowContentOverlay">@null</item>
</style>

</resources>
17 changes: 17 additions & 0 deletions templates/csharp/xplat/AvaloniaTest.Android/SplashActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Android.App;
using Android.Content;
using Application = Android.App.Application;

namespace AvaloniaTest.Android
{
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : Activity
{
protected override void OnResume()
{
base.OnResume();

StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>AvaloniaTest.NetCore</RootNamespace>
<AvaloniaVersion>0.10.12</AvaloniaVersion>
<!--Avalonia doesen't support TrimMode=link currently,but we are working on that https://github.com/AvaloniaUI/Avalonia/issues/6892 -->
<TrimMode>copyused</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
Expand All @@ -20,7 +18,6 @@
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AvaloniaTest\AvaloniaTest.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using Avalonia;
using Avalonia.ReactiveUI;

namespace AvaloniaTest.NetCore
namespace AvaloniaTest.Desktop
{
class Program
{
Expand All @@ -17,7 +16,6 @@ public static void Main(string[] args) => BuildAvaloniaApp()
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
.LogToTrace();
}
}
2 changes: 0 additions & 2 deletions templates/csharp/xplat/AvaloniaTest.Web/App.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Avalonia.ReactiveUI;
using Avalonia.Web.Blazor;

namespace AvaloniaTest.Web;
Expand All @@ -10,7 +9,6 @@ protected override void OnParametersSet()
base.OnParametersSet();

WebAppBuilder.Configure<AvaloniaTest.App>()
.UseReactiveUI()
.SetupWithSingleViewLifetime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.0" PrivateAssets="all" />
<PackageReference Include="Avalonia.Web.Blazor" Version="0.10.11" />
<PackageReference Include="Avalonia.Web.Blazor" Version="$(AvaloniaVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions templates/csharp/xplat/AvaloniaTest.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Foundation;
using UIKit;
using Avalonia;
using Avalonia.Controls;
using Avalonia.iOS;
using Avalonia.Media;

namespace AvaloniaTest.iOS
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : AvaloniaAppDelegate<App>
{

}
}
22 changes: 22 additions & 0 deletions templates/csharp/xplat/AvaloniaTest.iOS/AvaloniaTest.iOS.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-ios</TargetFramework>
<SupportedOSPlatformVersion>10.0</SupportedOSPlatformVersion>
<ProvisioningType>manual</ProvisioningType>
<Nullable>enable</Nullable>
<RuntimeIdentifier>iossimulator-x64</RuntimeIdentifier>

<!-- These properties need to be set in order to run on a real iDevice -->
<!--<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>-->
<!--<CodesignKey></CodesignKey>-->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia.iOS" Version="$(AvaloniaVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AvaloniaTest\AvaloniaTest.csproj" />
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions templates/csharp/xplat/AvaloniaTest.iOS/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
47 changes: 47 additions & 0 deletions templates/csharp/xplat/AvaloniaTest.iOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>AvaloniaTest</string>
<key>CFBundleIdentifier</key>
<string>companyName.AvaloniaTest</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
<string>10.0</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>
15 changes: 15 additions & 0 deletions templates/csharp/xplat/AvaloniaTest.iOS/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using UIKit;

namespace AvaloniaTest.iOS
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
}
Loading

0 comments on commit 15ef231

Please sign in to comment.