• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

anaisbetts/starter-mobile: Starter project for Mobile projects at GitHub

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

anaisbetts/starter-mobile

开源软件地址(OpenSource Url):

https://github.com/anaisbetts/starter-mobile

开源编程语言(OpenSource Language):

C# 86.3%

开源软件介绍(OpenSource Introduction):

Starter Project for Mobile Applications

This project is a base project for cross-platform mobile applications that should help you get started quicker without hours of right-clicking.

Are you using Xamarin.Forms?

Before you run the "Get Started" code, run the following command which is a branch configured to use ReactiveUI-XamForms and creates Xamarin Forms-based views.

git reset --hard xam-forms

How do I get started?

git clone https://github.com/paulcbetts/starter-mobile
script/create NameOfMyNewProject
git remote set-url origin https://github.com/MyUserName/NameOfMyNewProject
git push -u origin master

NOTE: Don't use a '.' in any of your project names, iOS gets hella upset. Yes, I think it'd look way better than '-' too.

How do I build the project

script/cibuild

What's the project structure here?

  1. Starter-Android: The main Android app project.
  2. Starter-iOS: The main iOS (both iPhone and iPad) application project.
  3. Starter-Core: Code that is shared between the two projects. This project also has Xamarin.Forms set up and ready to go.

Philosophy

How does this MVVM Thing Work™?

The idea is, that we want to create our models (i.e. stuff we save to disk and stuff we send over the network) and ViewModels (a class that represents the behavior of an app screen, by describing how properties are related to each other) in the Starter-Core library.

Ideally, the vast majority of our app will live in this library, because everything we don't put in here we have to write twice, and is super hard to test.

In this app, what we mean by "View" is, on iOS is a UIViewController and friends, and on Android is usually an Activity. Both of these classes are hard to test, so we want them to be as dumb as possible.

Here are some things that belong in Starter-Core:

  1. Anything related to sending stuff to the network
  2. Anything related to loading/saving user's data
  3. All of our ViewModel classes (i.e. for every screen in the app, we'll have a ViewModel class)

So, it's important that Starter-Core not do platform-specific things - if you're talking about CGRects in a Starter-Core class, you're Doing It Wrong™.

Here are some things that will end up in Starter-{Platform}

  1. The app startup code (i.e. AppDelegate)
  2. A ViewController or Activity for every screen in the app.

"How Do I?"

How do I add a new screen to the app?

  1. Create a new ViewModel class in Starter-Core and derive it from ReactiveObject. Put all of the interesting code in here - calling REST APIs, validating stuff, you name it!
  2. Walk over to the iOS project, create a new "Universal View Controller", copy paste some of the stuff from TestViewController (like the base class ReactiveViewController, and that boilerplate ViewModel property at the bottom)
  3. In the Android project, create a new Activity, same deal around the boilerplate there too.

How do I do interesting stuff in the core library when I can't access UI elements or other stuff??

You should define an Interface, then let the platforms implement. Here's how you could do this with an example UI action (note that this isn't the best way to do this, it's just an example):

First, define an interface in the Core project:

public interface IAlertHelper
{
    void ShowAlert(string message);
}

Then, in your ViewModel, you should make it a constructor parameter - we write it this way so that if we want to replace it with a dummy version in a test runner, it's easy to do:

public TestViewModel(IAlertHelper alertHelper = null)
{
    alertHelper = alertHelper ?? Locator.Current.GetService<IAlertHelper>();
    alertHelper.ShowAlert("Wat it do.");
}

Now, in the iOS and Android projects, you can register an implementation of this interface:

public class AppleAlertHelper : IAlertHelper
{
    public void ShowAlert(string message)
    {
        /* ... */
    }
}

and in your AppDelegate, you can register it:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    Locator.CurrentMutable.RegisterConstant(new AppleAlertHelper(), typeof(IAlertHelper));
}



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap