Commit Graph

486 Commits

Author SHA1 Message Date
Max Desiatov 82111c54a0
Set versions of dependencies in `Package.swift` (#262)
This allows specifying 0.3 (to be released after this PR is merged) dependency on Tokamak in `carton` templates, otherwise branch/commit dependencies in our `Package.swift` can't be correctly resolved.

`swift test` is temporarily disabled on macOS as the upstream Swift toolchain doesn't support unsafe flags in the JavaScriptKit dependency together with a `from` constraint. We could run it on Linux, but my OpenCombine fork doesn't support Linux builds yet (logged as #263).
2020-08-19 10:08:00 +01:00
Max Desiatov d97a5f3215
Update `CHANGELOG.md` for 0.3.0 release 2020-08-17 18:31:31 +01:00
Max Desiatov 2383a17c2d
Implement `StateObject` property wrapper (#260)
Resolves #158.

Fixes a bug where `NavigationView` destination was reset after scene phase changes (or any re-renders caused by environment changes for that matter).

This was caused by `@ObservedObject` destination being recreated, now `@StateObject` persists it across re-renders.

The `setter` property of the `ValueStorage` protocol is now moved to a separate `WritableValueStorage` protocol. The reasoning is that `StateObject` doesn't need its wrapped value to be set directly as it operates on it by reference, not by value, thus `StateObject` doesn't need any wrapped value setters.
2020-08-17 16:01:49 +01:00
Max Desiatov b9f5ef07ab
Fix `NavigationView` broken state after re-render (#259) 2020-08-15 18:07:19 +01:00
Max Desiatov b7434a2e54
Add `GeometryReader` implementation (#239)
This is just an empty API at the moment. I hope it can be implemented purely in the `deferredBody` of `GeometryReader` with [the ResizeObserver API](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver) without requiring any tweaks in the `Renderer` protocol or the reconciler.

Seems like I need the `domRef` modifier that writes `JSObjectRef` to a given binding working first, as discussed in #231.
2020-08-11 16:47:12 +01:00
Carson Katri c43d2db1b3
Add default dark styles for Views (#241) 2020-08-10 16:05:53 -04:00
Max Desiatov 2a49b7808b
Link to the renderers guide from `README.md` (#251)
* Link to the renderers guide from `README.md`

The guide itself was merged into a single file for easier navigation.

* Update RenderersGuide.md
2020-08-07 16:01:27 +01:00
Max Desiatov e11effdd8c
Use the latest 5.3 snapshot in `.swift-version` (#252)
* Use the latest 5.3 snapshot in `.swift-version`

These SwiftWasm snapshots should be more stable in general and also have a workaround for https://github.com/swiftwasm/JavaScriptKit/issues/6 included. They still use the old metadata layout, so Runtime and OpenCombine dependencies had to be updated in `Package.swift` for `@ObservableObject` to work with these snapshots.

* Fix linter warning
2020-08-06 13:57:36 +01:00
Max Desiatov de37894f83
Fix color scheme observer crashes in Safari (#249)
Resolve #245. Turns out `matchMediaDarkScheme` object doesn't have `addEventListener`, but only `addListener` in Safari 13.1.2.
2020-08-05 17:30:50 +01:00
Max Desiatov c4c9eb595e
Update to the latest version of SwiftFormat (#250)
* Update to the latest version of SwiftFormat

This fixes inconsistencies in argument and parameter formatting that we previously had.

* Fix function length in `Path.swift`

* Fix linter warnings

* More formatting cleanups

* Add `StrokeStyle.zero` in the `StaticHTML` module
2020-08-05 17:30:19 +01:00
Jed Fox 88064fd5bc
Split demo list into sections (#243)
* Split demo list into sections

* Remove slider demo

* Update RedactDemo.swift

* Redact → Redaction, move DOM refs to a TokamakDOM section, additional adjustments

* RedactDemo → RedactionDemo
2020-08-04 06:49:43 -04:00
Max Desiatov 62c05ae9aa
Remove some `AnyView` in the `List` implementation (#246) 2020-08-04 07:38:27 +01:00
Max Desiatov b93be40a19
Add `_targetRef` and `_domRef` modifiers (#240)
Resolves partially #231. `_targetRef` is a modifier that can be used by any renderer, while `_domRef` is an adaptation of that for `DOMRenderer`. Both are underscored as they are not available in SwiftUI, and also their stability is currently not so well known to us, we may consider changing this API in the future.

Example use:

```swift
struct DOMRefDemo: View {
  @State var button: JSObjectRef?

  var body: some View {
    Button("Click me") {
      button?.innerHTML = "This text was set directly through a DOM reference"
    }._domRef($button)
  }
}
```

I've also fixed all known line length warnings in this PR.
2020-08-02 22:01:38 +01:00
Max Desiatov c7b5e75e1a
Add `ColorScheme` environment (#136)
You can see the dark scheme environment text representation updated in `EnvironmentDemo`. I suggest adding default dark mode styles in a separate PR, I've created #237 as a reminder for that.
2020-08-02 18:55:35 +01:00
Carson Katri 70d31b2e5b
Add `redacted` modifier (#232) 2020-08-01 17:18:23 -04:00
Carson Katri 4c654da456
Add Static HTML Renderer and Documentation (#204) 2020-08-01 16:27:12 -04:00
Max Desiatov fbb893739b
Fix tests, move DefaultButtonStyle to TokamakCore (#234)
Merging #214 broke the tests. Also, `DefaultButtonStyle` seems to be trivial enough to be shared through `TokamakCore` between all renderers.
2020-08-01 20:07:10 +01:00
Max Desiatov 050e917161
Add `test-suite` label to `label.yml` 2020-08-01 19:41:25 +01:00
Max Desiatov 40804d4542
Remove `DefaultApp`, make `DOMRenderer` internal (#227)
Removes the `View`-based initializer of `DOMRenderer` which no longer leaves any `public` initializers on it, means we can make it fully internal. `DOMNode` is now internal too, which is great as it was an implementation detail anyway. Corollary, `DefaultApp` is no longer needed.

`Target` was cleaned up is it doesn't need to hold `App` or `Scene` values, now it's just a simple protocol.

I've updated `README.md` to show usage of the `App` protocol in the basic example.

Closes #224.
2020-08-01 18:46:59 +01:00
Max Desiatov e37d13017c
Add basic `ButtonStyle` implementation (#214)
This based off the `buttonstyles` branch by @Outcue.

Initially it didn't work because mounted host views didn't propagate their environment on updates. This is now fixed by adding `updateEnvironment` function on `MountedElement` base class and calling it in the initializer. Manual environment updates are no longer needed in `makeMounted...` factory functions. `makeMountedApp` is no longer needed at all and `MountedApp` initializer can be used directly then.
2020-08-01 18:46:34 +01:00
Max Desiatov 2c539d9319
Make reconciler tests build and run on macOS (#229)
We can't run our basic reconciler tests in a WASI environment yet because `XCTestExpectation` is not available on WASI as it relies on the presence of `Dispatch`. We can run these tests on macOS though, and even on Linux in the future when Swift 5.3 is available for Linux on GitHub Actions.

My current OpenCombine fork doesn't build on macOS and it was much easier to add a new `CombineShim` module that uses native Combine there.
2020-07-30 16:48:09 +01:00
Max Desiatov 1271281b75
Fix environment changes causing remounted scenes with lost state (#223)
Implements support for custom scenes by adding the new `MountedScene` type and fixes environment propagation from mounted parent to mounted child elements.

This will unblock https://github.com/swiftwasm/Tokamak/pull/136 and potentially https://github.com/swiftwasm/Tokamak/pull/214. In the former scenes are always completely unmounted and remounted from scratch when root environment changes, which causes descendants to lose all `@State` values. I saw some environment propagation issues in the latter, but not sure if those were caused by the lack of correct scene updates, just wanted to tackle the usual suspects first.

I've also improved reconciler-related doc comments to clarify some of the design desicions and naming.

Resolves #222.
2020-07-29 21:37:38 +01:00
Max Desiatov 7c6b1812ae
Add `DefaultApp` type to simplify `DOMRenderer.init` (#217)
This means that the `View` initializer of `DOMRenderer` now can delegate to the `App` initializer by creating a wrapping `DefaultApp`. It would simplify https://github.com/swiftwasm/Tokamak/pull/136 for me, where I no longer need to implement color scheme observation for these two different codepaths separately.
2020-07-29 09:26:08 +01:00
Outcue 8041732dc9
Implement `SidebarListStyle` (#210)
First pass at the SidebarListStyle.

For this to be truly complete, work needs to be completed on ButtonStyles. I can look at that next. NavigationLinks in a Sidebar are Text items that draw a blue background when clicked (and perhaps when item is active.)

Co-authored-by: Gene Z. Ragan <diskzero@mac.com>
Co-authored-by: Jed Fox <git@jedfox.com>
Co-authored-by: Gene Ragan <gene@semitone.audio>
2020-07-29 09:25:33 +01:00
Max Desiatov f5af009db2
Unify code of `MountedApp`/`MountedCompositeView` (#219)
We currently have the reconciler code duplicated in these types. I also have a draft `MountedScene` implementation, which most probably would rely on the same reconcilliation algorithm. In this PR it's made generic and can be shared across these types of mounted elements.
2020-07-28 18:01:29 +01:00
Max Desiatov 66248448ab
Generalize style and environment in `DOMRenderer` (#215)
Moves `DOMNode` to a separate file and reduces style and environment duplication in overloaded `DOMRenderer` initializers.
2020-07-27 09:36:08 +01:00
Carson Katri c68c70a7d7
Implement `DynamicProperty` (#213) 2020-07-25 17:32:28 -04:00
Max Desiatov a24f49f298
Warn against beta versions of Xcode in README.md (#207)
Seems like Xcode beta 3 is particularly problematic.Seems like Xcode 12 beta 3 is particularly problematic due to https://github.com/swiftwasm/carton/issues/65
2020-07-23 21:58:19 +01:00
Max Desiatov e372075ab6
Fix typo in `TokamakDemo.swift` (#206) 2020-07-23 13:46:03 +01:00
Max Desiatov f15f598d7b
Update "Requirements" and "Getting started" README sections (#205)
I hope this makes `README.md` a bit more friendly for our early adopters, but any feedback is welcome as usual 🙂
2020-07-22 22:27:19 +01:00
Jed Fox ac50208447
Initial `NavigationView` implementation (#130)
* Initial NavigationView implementation

* Make the _ButtonProxy type more generic

* Split Navigation.swift files

* Move this too

* Implement Navigation controls

* Update progress.md

* Make NavigationLinks links

* Break line

(wishing for Prettier for Swift)

* Update Path.swift

* n-th time’s the charm

* Update Path.swift

* Update project.pbxproj

* Fixes

* Hopefully fix build issues

* Update Navigation.swift

* Improve ColorDemo

* Fixes & reverts

* Fix crash

* Revert "Fix crash"

This reverts commit ae6f13dcc9.

* Tweak rendering of demos

* add todo for accessibility

* Apply suggestions from @MaxDesiatov

Co-authored-by: Max Desiatov <max@desiatov.com>

* Update TokamakDemo.swift

* Move things to Core.swift

* Switch default destination to EmptyView

* Fix build for macOS

* Revert "Apply suggestions from @MaxDesiatov"

This reverts commit 73c9c3f6ac.

Co-authored-by: Max Desiatov <max@desiatov.com>
Co-authored-by: Carson Katri <Carson.katri@gmail.com>
2020-07-22 17:12:15 -04:00
Carson Katri 2b93f37d64
Add SwiftUI App Lifecycle (#195) 2020-07-22 16:57:33 -04:00
Carson Katri 3aec3b7e4b
Add `Path._Sizing`, `foregroundColor` modifier (#200) 2020-07-22 16:30:39 -04:00
Max Desiatov 6e4e93602a
Bump JavaScriptKit to 0.5.0 (#201)
This change is required to make Tokamak compatible with `carton` 0.4, which bundles the latest JavaScriptKit runtime. Currently the new runtime and old Swift parts of JavaScriptKit are incompatible with each other, which leads to a white screen when building and running Tokamak from `main` with `carton` 0.4.

It's already a part of a couple of other PRs, but opening this one separately to expedite it as `carton` 0.4 is already released. I haven't announced it widely yet, so I hope we can merge this in quickly to avoid any confusion among our early adopters who try to use Tokamak with the latest version of `carton` 🙂
2020-07-22 16:32:10 +01:00
Max Desiatov ddf3e868bd
Update CHANGELOG.md for 0.2.0 release 2020-07-21 19:47:07 +01:00
Max Desiatov 146ef33aa8
Move view files to separate subdirectories (#194)
These files are organized mostly according to their functionality. Some of these subdirectories still have a single file, but will have multiple when more views are implemented.
2020-07-21 10:25:23 +01:00
Max Desiatov 5ebf5a5dc8
Add `UIColor` stub and new `Color.init(_:UIColor)` (#196) 2020-07-21 08:14:51 +01:00
Jed Fox f0e2b054dc
Add Toggle implementation (#159)
* Fix Button.body

* Add support for renderers customizing default environment values

* Add ParentView conformances

* Add Toggle

* long lines

* Update Path.swift

* Update Path.swift

* Update Sources/TokamakDOM/DOMRenderer.swift

Co-authored-by: Max Desiatov <max@desiatov.com>

* bodyBuild → bodyClosure

* Update progress.md

* Update progress.md, implement Toggle(_ configuration: ToggleStyleConfiguration)

* Fix demo on native

* Hopefully fix issue

* Hopefully fix issue for real

* maybe this will work

* Update ToggleDemo.swift

* AnyToggleStyle → _AnyToggleStyle

* Fix remaining AnyToggleStyle

* Clean up unnecessary files

* Move typealias to Core.swift

* Revert change to ListDemo, remove unused let

Co-authored-by: Max Desiatov <max@desiatov.com>
2020-07-20 18:21:32 -04:00
Max Desiatov 5f3822257d
Add `TokamakShim` module to simplify imports (#192)
Adding this module as a dependency, Tokamak users would only need to add a single import regardless of the platform they're targeting. Thus, instead of

```swift
#if canImport(SwiftUI)
import SwiftUI
#else
import TokamakDOM
#endif
```

a single `import TokamakShim` is enough. `TokamakShim` re-exports correct modules based on a target platform.

I've also renamed the `TokamakDemo Native` directory to `NativeDemo` for brevity.

`xcodebuild` output in the `macos_demo_build` job is now passed to `xcpretty` for more readable build logs.
2020-07-19 20:53:27 +01:00
Jed Fox 743d9a0de8
Organize all the re-exports into a single file (#193)
* Organize all the re-exports into a single file

Hypothetically, Core.swift could be copy-pasted unmodified into any renderer

* Update ZStack.swift
2020-07-19 10:46:19 -04:00
Max Desiatov b495a2447d
Add `Picker` and `PopUpButtonPickerStyle` as default (#149)
The rest of the styles will be implemented as separate PRs.

Additionally, `LazyHGrid` demo is wrapped in a horizontal `ScrollView` so that it can be viewed in portrait phone layout in the native demo.
2020-07-17 12:57:40 +01:00
Carson Katri 93927f41f5
Add @EnvironmentObject (#170) 2020-07-17 07:54:49 -04:00
Jed Fox 314a6f3a5a
Allow non-consecutive state variables (#191)
* Fix error when state variables are non-consecutive

* Update one of the demos to cause it to fail without the fix
2020-07-16 17:10:09 -04:00
Max Desiatov ffa686c7dc
Add @ObservedObject implementation (#171)
This pulls a fork of OpenCombine that can be compiled with the same SwiftWasm snapshot we use in `main`.

The only caveat is that this doesn't work for `ObservableObject`s that are subclasses of other classes with `@Published` properties. This issue needs to be fixed in [the Runtime library fork](https://github.com/MaxDesiatov/Runtime). Since this is a rare case, and fixing it wouldn't change this `@ObservedObject` implementation, I think it's ready for review as is.
2020-07-16 20:39:47 +01:00
Max Desiatov 8f23ac979f
Avoid AnyView in the Counter code (#168)
It's not needed there as `ViewBuilder` is smarter now.

The macOS SwiftUI SDK even with Xcode 12 still doesn't have the `@ViewBuilder` attribute on the `View` protocol, so we have to build for iOS on CI to make the native buld pass.

Resolves #167, which wasn't caused by protocol conformance problems, but by infinite recursion in the `_ConditionalContent` implementation of `body`.

Adds assorted formatting fixes, some are apparently caused by the newer `swiftformat` version.
2020-07-16 19:17:04 +01:00
Max Desiatov 31d90fd129
Fix wording in README.md 2020-07-15 21:43:29 +01:00
Max Desiatov d172e04f7c
Mention `#webassembly` SwiftPM Slack channel in README.md (#187)
Was asked about this a few times in the last few days, probably worth surfacing it in `README.md` 🙂
2020-07-15 12:17:02 +01:00
Carson Katri 11af0f8d98
Add LazyHGrid and LazyVGrid (#179)
* Add LazyHGrid and LazyVGrid

* iOS support & progress doc
2020-07-14 13:28:23 -04:00
Max Desiatov 9cf606ef0c
Implement `static func Binding<Value>.constant` (#178)
Unrelated formatting changes were added by the SwiftFormat pre-commit hook.
2020-07-13 16:36:27 +01:00
Carson Katri 2b3010a631
Match SwiftUI Color (#177) 2020-07-13 11:27:55 -04:00