Elm iOS

将 Elm 的奇迹带到 iOS 平台。(Bringing the wonders of Elm to the iOS platform.)

  • Owner: pzp1997/elm-ios
  • Platform: iOS
  • License:: BSD 3-Clause "New" or "Revised" License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Elm iOS(榆树iOS)

将 Elm 的奇迹带入 iOS 平台。

当前状态

我已经证明可以使用 Elm 创建本机移动应用程序,成功实现了我今年夏天的目标。 也就是说,该项目仍处于早期的 alpha 阶段,绝对不应该用于生产应用程序。 目前,该项目仅支持 UIKit 元素的一小部分,这意味着它没有纯粹在 Obj-C/Swift 中编写的应用程序的完整表现力。

展望未来,我打算积极维护这个项目,但是,当我在大学时,新的开发将会放缓。 如果您有兴趣参与,请阅读以下部分。

用法

由于 Elm iOS 包含内核代码,因此您无法使用 elm-package install 安装它。 出于这个原因,我建议使用 elm-github-install 来安装它。 要沿着这条路走下去,你的 elm-package.json 文件看起来应该是这样的。

{
    "version": "1.0.0",
    "summary": "helpful summary of your project, less than 80 characters",
    "repository": "https://github.com/user/project.git",
    "license": "BSD3",
    "source-directories": [
        "."
    ],
    "exposed-modules": [],
    "dependencies": {
        "elm-lang/core": "5.1.1 <= v < 6.0.0",
        "pzp1997/elm-ios": "0.1.0 <= v <= 0.1.0"
    },
    "dependency-sources": {
      "pzp1997/elm-ios": "https://github.com/pzp1997/elm-ios.git"
    },
    "elm-version": "0.18.0 <= v < 0.19.0"
}

软件包中包含一个名为 elm-ios.py 的 CLI 脚本。这个脚本是 elm-make 的包装器,应该用于编译 Elm iOS 应用程序。除了以下方面之外,选项和标志的行为与 elm-make 相同。

  1. 添加了一个名为 --name 的新标志,用于指定应用程序的包标识符。通常使用反向域名表示法来编写包标识符,例如, com.palmerpaul.MyAwesomeApp。
  2. --output 标志被忽略。

当您运行脚本时,它将在您编译的 Elm 程序和静态资源的 ios/ 目录中创建一个 Xcode 项目。从那里,您可以打开 .xcworkspace 文件以使用 Xcode 运行或修改项目。请注意,每次运行脚本时,它都会清理 ios/ 目录,因此为防止数据丢失,请尽量不要在其中存储重要内容。

为了使此过程成功运行,我们已经建立了两个命名限制。

  1. 您编译的 Elm 模块必须命名为 Main。这意味着传递给 elm-ios.py 的 Elm 文件的第一行应该是模块 Main exposureing(..)。 (一旦这个项目与 Elm 编译器正确集成,这个限制很可能会解除。)
  2. 您要与应用程序捆绑在一起的所有静态资产必须位于项目目录中的名为 assets/ 的目录中(elm-package.json 文件所在的目录)。

专业提示:安装软件包后,我建议将 elm-ios.py 脚本从 elm-ios 软件包目录移动到项目目录,以便于运行。您可以通过运行命令 cp elm-stuff/packages/pzp1997/elm-ios/0.1.0/elm-ios.py . 来完成此操作。

例子

下面是我创建的一些示例,用于演示此项目的功能。 如果您使用 Elm iOS 制作一些很酷的东西,请告诉我,以便它可以在这里展示。

Main metrics

Overview
Name With Ownerpzp1997/elm-ios
Primary LanguageC
Program languagePython (Language Count: 8)
PlatformiOS
License:BSD 3-Clause "New" or "Revised" License
所有者活动
Created At2017-08-23 04:18:11
Pushed At2018-09-08 21:43:11
Last Commit At2018-01-18 10:29:31
Release Count1
Last Release Namev0.1.0 (Posted on 2017-08-31 15:33:22)
First Release Namev0.1.0 (Posted on 2017-08-31 15:33:22)
用户参与
Stargazers Count160
Watchers Count13
Fork Count7
Commits Count38
Has Issues Enabled
Issues Count2
Issue Open Count2
Pull Requests Count0
Pull Requests Open Count1
Pull Requests Close Count2
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Elm iOS

Bringing the wonders of Elm to the iOS platform

Current Status

I have shown that it is possible to use Elm to create native mobile apps, succeeding in my stated goal for the summer. That said, the project is still in an early alpha stage and definitely should not be used for production apps yet. Currently, the project supports only a small subset of the UIKit elements, meaning that it does not have the full expressive power of an app written purely in Obj-C/Swift.

Looking ahead, I intend to actively maintain the project, however, new development will slow down while I am at university. If you are interested in contributing, read the section below.

Usage

Since Elm iOS contains Kernel code, you cannot yet install it using elm-package install. For this reason, I recommend using elm-github-install to install it. To go down this route, your elm-package.json file should look something like this.

{
    "version": "1.0.0",
    "summary": "helpful summary of your project, less than 80 characters",
    "repository": "https://github.com/user/project.git",
    "license": "BSD3",
    "source-directories": [
        "."
    ],
    "exposed-modules": [],
    "dependencies": {
        "elm-lang/core": "5.1.1 <= v < 6.0.0",
        "pzp1997/elm-ios": "0.1.0 <= v <= 0.1.0"
    },
    "dependency-sources": {
      "pzp1997/elm-ios": "https://github.com/pzp1997/elm-ios.git"
    },
    "elm-version": "0.18.0 <= v < 0.19.0"
}

Included in the package is a CLI script called elm-ios.py. This script is a wrapper around elm-make that should be used for compiling Elm iOS apps. The options and flags behave identically to elm-make except for in the following regards.

  1. A new flag called --name has been added for specifying the bundle identifier for your app. The bundle identifier is typically written using reverse domain name notation, e.g. com.palmerpaul.MyAwesomeApp.
  2. The --output flag is ignored.

When you run the script, it will create an Xcode project in the ios/ directory from your compiled Elm program and static assets. From there, you can open the <NAME_OF_YOUR_APP>.xcworkspace file to run or modify the project using Xcode. Note that each time the script is run it will clean the ios/ directory, so to prevent data loss, try not to store anything important in there.

In order to make this process successfully work, there are two naming restrictions that we have established.

  1. The Elm module that you compile must be named Main. This means that the first line of the Elm file that you pass to elm-ios.py should be module Main exposing (..). (Once this project is properly integrated with the Elm compiler, this restriction will likely be lifted.)
  2. All static assets that you want to bundle with your app must be in a directory named assets/ located in your project directory (where your elm-package.json file lives).

Pro Tip: Once you install the package, I recommend moving the elm-ios.py script from the elm-ios package directory to your project directory to make it easier to run. You can do this by running the command cp elm-stuff/packages/pzp1997/elm-ios/0.1.0/elm-ios.py ..

Examples

Below are some examples that I created to demonstrate the capabilities of this project. If you make something cool with Elm iOS, please let me know so that it can be featured here.

Documentation

There is no documentation for this project yet. This decision was made somewhat intentionally in order to emphasize the experimental nature of this project. For the time being, in lieu of documentation here are some high-level tips to help you should you choose to experiment with this project.

Currently, there are five elements available to you: row, column, label, button, image. row and column accept a list of attributes and a list of children, while the others accept only a list of attributes.

These five elements accept most of the attributes of their corresponding UIKit element (those that are not allowed violate the principles of the Elm architecture), so the UIKit documentation is a good place to look for details about them. row and column correspond to UIView, and label, button, and image correspond to UILabel, UIButton, and UIImageView respectively.

Since we use Yoga as our layout engine, all flexbox properties should be supported. For more details about layout attributes, consult the Yoga documentation.

In addition to this advice, you can look at the examples for guidance. If you are genuinely stuck on something, feel free to open a GitHub issue.

Limitations

There are some limitations to this project. I do not believe that any of these limitations are insurmountable given sufficient time to work on them.

  • Many UIKit elements are missing, i.e. UINavigationBar, UITabBar, UITableView, UITextView, UISlider, UISwitch, etc.
  • There is no way to interact with the device APIs
  • Keyed nodes are not supported
  • "Attributed text" (text with fine-grained styling) is not supported

Blog Posts

Throughout the summer, I authored a series of blog posts giving status updates on the project. These blog posts can be a useful resource to those who are interested in understanding the reasoning behind some of the major design choices that I made.

History

This project started as a Google Summer of Code project. After trying out Elm for about a week, I realized that I wanted to spend my summer working with the Elm Software Foundation. When searching for project ideas, I stumbled across ohanhi/elm-native-ui which is a library that uses React Native to create mobile Elm apps. After meeting with Ossi and Evan to discuss the possibility of working on that project for the summer, we decided that it would be best to try to create an Elm iOS solution that does not rely on third-party frameworks. I submitted a proposal for what would ultimately become this project and was accepted for the Google Summer of Code program.

This repo is comprised of work from three other repos (although all further development on elm-ios will happen here). The Elm code and JavaScript Kernel code, which now live in src/, were originally developed in pzp1997/virtual-dom. The Swift code for the app template, which now lives in AppTemplate, originated in pzp1997/elm-ios-bridge. Lastly, the examples from examples/ were mainly developed in pzp1997/elm-ios-examples. If you are interested in the early commit history of the project, you should definitely take a look at those repos.

Contributing

If you are interested in contributing, contact me before you start working on the project. Doing so makes it easier for me to help you, allows us to use our resources most effectively, and ensures that your efforts will not be in vain. There are plenty of tasks of varying difficulty and time commitment that you can help out with. Please check out CONTRIBUTING.md and contact me for more info.

Acknowledgements

First and foremost, I would like to thank Evan Czaplicki for mentoring me this summer. Your advice and insights during our weekly planning sessions were incredibly helpful. I would also like to thank Matthew Griffith for providing me with a space to work and making me feel welcome in the Elm community. Last but certainly not least, I would like to thank my parents for supporting me, being there for me whenever I would discover a serious bug or design flaw, and for always rooting for me.

Contact Info

Palmer Paul
pzpaul2002@yahoo.com
palmerpa on the elm-lang Slack