neo-6m uno
First, we should start off with what Uno is and why you should care.
首先,我們應該從Uno是什么以及為什么要關心開始。
As stated on their website, Uno is "The only platform for building native mobile, desktop and WebAssembly apps with C#, XAML from a single codebase. Open source and professionally supported."
如其網站上所述 ,Uno是“唯一的平臺,可通過單一代碼庫使用C#,XAML構建本機移動,桌面和WebAssembly應用程序。開源且受到專業支持。”
這是什么意思? (What does this mean?)
Well if you have any experience (or not) building a mobile app and a subsequent web app, you have essentially had to build both separately, outside of potentially sharing data through an API.
好吧,如果您有(或沒有)構建移動應用程序和后續Web應用程序的經驗,那么除了通過API可能共享數據之外,您實際上必須分別構建兩者。
Before Xamarin, you would even have had to build the iOS and Android apps separately using different languages (Swift/Objective-C and Java/Kotlin respectively). Uno introduces a way to build for iOS, Android, Web, and UWP using shared logic and UI.
在使用Xamarin之前,您甚至不得不使用不同的語言(分別為Swift / Objective-C和Java / Kotlin)分別構建iOS和Android應用程序。 Uno引入了一種使用共享邏輯和UI為iOS,Android,Web和UWP進行構建的方法。
This is huge.
這是巨大的。
Sharing logic between platforms has been the "easy" part for developers. Sharing UI, however, is not. There is a huge difference in UI between Android and iOS and even larger differences between web and mobile. Xamarin.Forms allows us to share UI for Android and iOS but we were still on our own for the web.
平臺之間共享邏輯一直是開發人員的“輕松”部分。 但是,不是共享UI。 Android和iOS之間的UI差異巨大,網絡和移動設備之間的差異甚至更大。 Xamarin.Forms允許我們共享Android和iOS的UI,但在網絡上我們仍然靠自己。
Uno enables you to write the UI once, then, using native controls, deploys native UI look and feel to each of your platforms. This means, you write the same code for a button regardless of the platform the button is for, and the user will see the native button for their platform.
Uno使您可以編寫一次UI,然后使用本機控件將本機UI外觀部署到每個平臺。 這意味著,無論按鈕用于哪個平臺,都為該按鈕編寫相同的代碼,并且用戶將看到其平臺的本機按鈕。
它是如何工作的? (How does it work?)
The Uno Platform works differently depending on what you're building.
Uno平臺的工作方式取決于您所構建的內容。
The platform specific UI is created by taking the visual tree and rendering into what the platform supports:
通過將可視化樹并渲染為平臺支持的內容來創建特定于平臺的UI:
iOS - UI Kit
iOS - UI套件
Android - ViewGroups and Views
Android的 - ViewGroups和視圖
Web - Native controls
網絡 -本地控制
The logic is also deployed differently for each platform.
每個平臺的邏輯部署也不同。
When building a UWP app, Uno runs on top of, well, UWP and WinUI. When building Android and iOS apps, Uno runs on top of the Xamarin Native Stack. Finally, when you're building a Web App, Uno runs on top of WebAssembly. The mobile apps and web apps all run with Mono runtime. When it all comes together, it looks a little like this:
在構建UWP應用時,Uno可以運行在UWP和WinUI之上。 在構建Android和iOS應用程序時,Uno在Xamarin本機堆棧的頂部運行。 最后,當您構建Web應用程序時,Uno在WebAssembly之上運行。 移動應用程序和Web應用程序均與Mono運行時一起運行。 當所有這些放在一起時,看起來有點像這樣:
Well this looks nice, but what's really happening under the hood?
好吧,這看起來不錯,但是引擎蓋下到底發生了什么呢?
讓我們分解一下: (Let's break it down:)
Android and iOS
Android和iOS
- You write your C# and XAML code in Visual Studio 您在Visual Studio中編寫C#和XAML代碼
- Uno takes the code and lets you add any Xamarin specific libraries or tools Uno獲取代碼,并允許您添加任何Xamarin特定的庫或工具
- Mono runtime executes the C# code Mono運行時執行C#代碼
This process is essentially the same as regular Xamarin. The big difference between Xamarin and Uno comes with the ability to run the same UI on the Web.
此過程與常規Xamarin基本相同。 Xamarin和Uno之間的最大區別在于可以在Web上運行相同的UI。
Web Apps -
網絡應用 -
You reuse both your logic and UI ?that you wrote for your mobile apps.
您可以重用為移動應用程序編寫的邏輯和UI 。
Uno uses the Web Assembly Bootstrapper to take any .NET standard library and execute these files in the JavaScript console.
Uno使用Web Assembly Bootstrapper來獲取任何.NET標準庫并在JavaScript控制臺中執行這些文件。
- Mono runtime then executes the code 然后,Mono運行時執行代碼
The ability for Uno to utilize Web Assembly (which is what allows you to write your code in C# and not JavaScript) is what makes Uno so unique.
Uno能夠利用Web Assembly(這是使您可以用C#而不是JavaScript編寫代碼的能力)的能力使Uno如此獨特。
UWP -
UWP-
You reuse both your logic and UI ?that you wrote for your mobile apps and Web Assembly Apps.
您可以重用為移動應用程序和Web Assembly Apps編寫的邏輯和UI 。
- Your code is run through the Windows UI which does not need the Mono runtime to execute. 您的代碼是通過Windows UI運行的,不需要執行Mono運行時。
The big difference here is that UWP apps already have the Windows namespaces and do not need to reference the Uno.UI. The benefit Uno provides here is the ability to reuse the code you've already written for mobile and web.
這里的最大區別是UWP應用程序已經具有Windows名稱空間,并且不需要引用Uno.UI。 Uno在此提供的好處是可以重用您已經為移動設備和Web編寫的代碼。
Now that we have an idea of how this beauty works, let's write some code!
現在我們已經了解了這種美的原理,讓我們編寫一些代碼!
To get started with Uno, follow their instructions here.
要開始使用Uno,請按照此處的說明進行操作。
When you create your Uno solution in Visual Studio, there is a similar feel to when you create a Xamarin.Forms solution because of the different projects created for you. Here is a look at the projects that are auto-created:
在Visual Studio中創建Uno解決方案時,由于為您創建了不同的項目,因此與創建Xamarin.Forms解決方案時的感覺相似。 看一下自動創建的項目:
As you would see in a Xamarin.Forms project, there are separate projects for each platform and a single shared project. The Droid, iOS, UWP, and Wasm projects are all the same as if you had created a blank app for each, the only difference being references to the Uno UI. The magic happens in the Shared project.
正如您在Xamarin.Forms項目中看到的那樣,每個平臺都有單獨的項目,而單個共享項目也有。 Droid,iOS,UWP和Wasm項目與您為每個項目創建一個空白應用程序一樣,唯一的不同是對Uno UI的引用。 魔術發生在共享項目中。
Similar to the Shared project in Xamarin.Forms, this is where you will write all your shared logic and UI. Uno provides support for the MVVM, a design pattern many developers are familiar and comfortable with.
與Xamarin.Forms中的Shared項目相似,在這里您將編寫所有共享的邏輯和UI。 Uno提供了對MVVM的支持, MVVM是許多開發人員熟悉并熟悉的設計模式。
那么,成品看起來像什么? (So, what does a finished product look like?)
Using the example "Todo" app provided by Uno here, here are examples from each of the four platforms.
使用Uno 這里提供的示例“ Todo”應用程序,這里是來自四個平臺的示例。
iOS
的iOS
Android
安卓系統
Web
網頁
UWP
超人
These projects all use logic and UI from the shared project. Code once, four apps.
這些項目都使用共享項目中的邏輯和UI。 編寫一次,四個應用程序。
讓我們談談調試。 (Let's talk debugging. )
Debugging in Uno can be a bit different depending which platform you are trying to debug.
Uno中的調試可能會有所不同,具體取決于您要調試的平臺。
Android and iOS - For mobile, you will use the same Mono debugger you are used to using in Visual Studio, with access to all your favorite breakpoints, value changes, etc.
Android和iOS-對于移動設備,您將使用與Visual Studio中相同的Mono調試器,并可以訪問所有喜歡的斷點,值更改等。
Web - Currently there is only support for chromium debugging, which means Chrome and Edge.
網絡 -目前僅支持Chrome調試,即Chrome和Edge。
UWP - Here, the tooling comes from .NET studios which is not as efficient with the mono runtime.
UWP-在這里,該工具來自.NET Studio,這在Mono運行時中效率不高。
Want to try out Uno but don't want to go through the steps to get set up through Visual Studio?
是否想嘗試Uno,但不想執行通過Visual Studio進行設置的步驟?
Then checkout their playground!
然后結帳他們的游樂場 !
The Uno Playground is a fun and easy way to look at how different items render on different platforms. They make it quick and easy to try out new styles and is great for beginners and tutorials.
Uno Playground是一種有趣而簡單的方法,可以查看不同項目在不同平臺上的呈現方式。 它們使您可以輕松快捷地嘗試新樣式,非常適合初學者和教程。
我們可以期待哪些未來功能? (What are future features we can look forward to?)
- Support for MacOS or Linux. 支持MacOS或Linux。
- More features from UWP API UWP API的更多功能
- Support for smart watches 支持智能手表
The true beauty of Uno is that it encompasses what we as developers should all be striving to accomplish - building on top of each others' accomplishments. We don't need to re-create the wheel, real innovation happens when you stand on the shoulders of giants and we all move upwards.
Uno的真正優點在于它涵蓋了我們所有人作為開發人員都應努力實現的目標-建立在彼此的成就之上。 我們不需要重新制造輪子,當您站在巨人的肩膀上并且我們都向上移動時,真正的創新就會發生。
Happy coding.
快樂的編碼。
For more lessons and tips for Uno, checkout my blog.
有關Uno的更多課程和提示,請查看我的博客 。
翻譯自: https://www.freecodecamp.org/news/uno-platform/
neo-6m uno