在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):anaisbetts/starter-mobile开源软件地址(OpenSource Url):https://github.com/anaisbetts/starter-mobile开源编程语言(OpenSource Language):C# 86.3%开源软件介绍(OpenSource Introduction):Starter Project for Mobile ApplicationsThis 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 projectscript/cibuild What's the project structure here?
PhilosophyHow 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:
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}
"How Do I?"How do I add a new screen to the app?
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));
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论