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).
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.
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.
* 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
* 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
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.
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.
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.
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.
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.
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.
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.
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>
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.
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` 🙂
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.
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.
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.
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.
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.