Commit Graph

667 Commits

Author SHA1 Message Date
Max Desiatov af810902bd
Create `FAQ.md` (#511)
This is a document we could redirect people to with questions about our layout system, naming, and history of the project. Feel free to expand this with more relevant topics.

Co-authored-by: Carson Katri <Carson.katri@gmail.com>
2022-09-02 12:47:17 +00:00
BenedictSt b24b964fd7
Fix typos in doc comments across the codebase (#513) 2022-09-02 13:43:54 +01:00
Max Desiatov e7e318e64e
Disable GTK macOS builds (#512)
Errors started cropping up during CI runs on https://github.com/TokamakUI/Tokamak/pull/511. I think it's better to disable this job until we find a good way to fix it. It wasn't a job required for merging PRs anyway, as GTK renderer is currently experimental.
2022-09-02 13:43:08 +01:00
Max Desiatov 47c5a05068
Update default assignee in `bug_report.md` (#510) 2022-08-29 10:23:03 +01:00
Max Desiatov fa0a8d2447
Update maintainers list in `README.md` 2022-08-22 19:00:26 +01:00
Max Desiatov 687baee97f
Use Swift 5.7 nightly on CI, fix build issues (#507)
* Use Swift 5.7 nightly on CI to fix build issues

* Update SwiftWasm snapshots

* Remove initializers that became ambiguous in 5.7
2022-07-30 11:26:20 +02:00
Max Desiatov 10d9d32b97
Update maintainers list in `README.md` 2022-07-26 14:32:44 +01:00
Carson Katri 4e8b84e4a1
Allow window resizing in Fiber renderers (#502)
* Add publisher for sceneSize

* Resolve build issue

* Add documentation

* Fix double update issue
2022-07-06 08:45:49 -04:00
Carson Katri 676760d34b
Add support for preferences, `@StateObject`, `@EnvironmentObject`, and custom `DynamicProperty` types (#501)
* Pass preferences up the Fiber tree

* Working preferences (except for backgroundPreferenceValue)

* Initial StateObject support

* Fix layout caching bug

* Support StateObject/EnvironmentObject/custom DynamicProperty

* Add doc comments for bindProperties and updateDynamicProperties

* Use immediate scheduling in static HTML and test renderers

* Add preferences test

* Add state tests and improve testing API

* Attempt to fix tests

* Fix preference tests

* Attempt to fix tests when Dispatch is unavailable

* #if out on os(WASI)

* Add check for WASI to test

* Add check for WASI to TestViewProxy

* #if out of import Dispatch when os == WASI

* Remove all Dispatch code

* Remove address from debugDescription

* Move TestViewProxy to TokamakTestRenderer

* Add memory address to Fiber.debugDescription

* Fix copyright year

* Add several missing types to Core.swift

* Add missing LayoutValueKey to Core.swift

* Fix issues with view trait propagation

* Enable App/SceneStorage in DOMFiberRenderer

* Address review comments

* Revise preference implementation
2022-07-05 18:04:28 -04:00
Carson Katri 9d0e2fc067
Support `Image` in Fiber renderers (#500)
* Support image and aspect ratio

* Fix measureImage implementation in test renderer

* Improve accuracy of aspectRatio

* Rename intrinsicSize to hide from autocomplete
2022-06-28 20:04:42 +00:00
Carson Katri d78ab20ea8
Add `Layout` protocol for FiberReconciler (#498)
* Initial pass at Layout protocol implementation

* Move layout into a separate pass

* Split reconciler into separate FiberReconcilerPass-es

* Cleanup reconcile pass

* Simplify cache implementation

* Optimize array capacity and persist cache between runs

* Revert viewChildrenCount

* Improve accuracy of stack layout

* Try caching sizeThatFits

* Revise caching of sizeThatFits

* Cleanup layout files and split up

* Further cleanup

* Add ContainedZLayout

* Add frame layouts

* Add snapshots tests that compare against native SwiftUI

* Perform updates from the top of the view hierarchy for dynamic layout

* Add Package.swift

* Fix reconciler bug

* Add test case for reconciler insert bug

* Respect spacing preferences

* Revise cache and spacing logic to match SwiftUI default implementations

* Allow spacing changes based on adjacent View type

* Support view traits in FiberReconciler (and LayoutValueKey by extension)

* Propagate cache invalidation

* Cleanup attributes

* Simplify LayoutPass and improve accuracy

* Cleanup logs

* Add layoutPriority tests

* Revise conflict with main

* Dictionary performance catch

* Remove unneccesary capacity preservation

* Update TokamakCoreBenchmark to handle LayoutView addition at hierarchy root

* Implement AnyLayout and replace LayoutActions

* Allow VStack/HStack to be created without children

* Fix padding implementation

* Formatting fixes

* Space out ViewArguments.swift properties

* Add backing storage to LayoutSubview to move out of ReconcilePass and slightly optimize stack usage
2022-06-27 08:53:30 -04:00
Yuta Saito 5e6fe2d2c9
Fix build and tests for 5.7 toolchain (#499) 2022-06-26 03:42:37 +09:00
filip-sakel c4717d5cae
Implement `AnyShape` (#497)
* Implement AnyShape.

* Remove unnecessary body implementation.
2022-06-24 08:38:14 -04:00
ezraberch 0b182d99a1
Add file size to benchmark script (#496)
* * Add file size to benchmark script
* Reenable macOS TokamakDemo build in CI

* Update benchmark.sh

* Add Wasm size annotation

* Make sizes more readable
2022-06-24 08:36:35 -04:00
Carson Katri 546b9e572f
Add `_PaddingLayout` support to layout engine (#485)
* Initial Reconciler using visitor pattern

* Preliminary static HTML renderer using the new reconciler

* Add environment

* Initial DOM renderer

* Nearly-working and simplified reconciler

* Working reconciler for HTML/DOM renderers

* Rename files, and split code across files

* Add some documentation and refinements

* Remove GraphRendererTests

* Initial layout engine (only implemented for the TestRenderer)

* Layout engine for the DOM renderer

* Refined layout pass

* Revise positioning and restoration of position styles on .update

* Re-add Optional.body for StackReconciler-based renderers

* Add text measurement

* Add spacing to StackLayout

* Add benchmarks to compare the stack/fiber reconcilers

* Fix some issues created for the StackReconciler, and add update benchmarks

* Add BenchmarkState.measure to only calculate the time to update

* Fix hang in update shallow benchmark

* Fix build errors

* Address build issues

* Remove File.swift headers

* Rename Element -> FiberElement and Element.Data -> FiberElement.Content

* Add doc comment explaining unowned usage

* Add doc comments explaining implicitly unwrapped optionals

* Attempt to use Swift instead of JS for applying mutations

* Fix issue with not applying updates to DOMFiberElement

* Add comment explaining manual implementation of Hashable for PropertyInfo

* Fix linter issues

* Remove dynamicMember label from subscript

* Re-enable carton test

* Attempt GTK fix

* Add option to disable layout in the FiberReconciler

* Re-enable TokamakDemo with StackReconciler

* Restore CI config

* Restore CI config

* Add file headers and cleanup structure

* Add 'px' to font-size in test outputs

* Remove extra newlines

* Keep track of 'elementChildren' so children are positioned in the correct order

* Use a ViewVisitor to pass the correct View type to the proposeSize function

* Add support for view modifiers

* Add frame modifier to demonstrate modifiers

* Fix TestRenderer

* Remove unused property

* Add PaddingLayoutComputer

* Fix doc comment

* Fix doc comment

* Fix linter issues and refactor slightly

* Fix benchmark builds

* Attempt to fix benchmarks

* Fix sibling layout issues

* Restore original demo

* Address review comments

* Remove maxAxis and fitAxis properties

* Use switch instead of ternary operators

* Add more documentation to layout steps

* Resolve reconciler issue due to alternate child not being cleared/released

* Apply suggestions from code review

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

* Reuse Text resolution code.

* Add more documentation

* Fix typo

* Use structs for LayoutComputers

* Update AlignmentID demo

* Fix weird formatting

* Fix copyright year

* Restore original demo

* Move attribute to newline

* Address review comments

Co-authored-by: Max Desiatov <max@desiatov.com>
2022-06-15 10:34:13 -04:00
Carson Katri c935744ae8
Add `_ShapeView` and `background` modifiers support to Fiber renderers (#491)
* Initial Reconciler using visitor pattern

* Preliminary static HTML renderer using the new reconciler

* Add environment

* Initial DOM renderer

* Nearly-working and simplified reconciler

* Working reconciler for HTML/DOM renderers

* Rename files, and split code across files

* Add some documentation and refinements

* Remove GraphRendererTests

* Initial layout engine (only implemented for the TestRenderer)

* Layout engine for the DOM renderer

* Refined layout pass

* Revise positioning and restoration of position styles on .update

* Re-add Optional.body for StackReconciler-based renderers

* Add text measurement

* Add spacing to StackLayout

* Add benchmarks to compare the stack/fiber reconcilers

* Fix some issues created for the StackReconciler, and add update benchmarks

* Add BenchmarkState.measure to only calculate the time to update

* Fix hang in update shallow benchmark

* Fix build errors

* Address build issues

* Remove File.swift headers

* Rename Element -> FiberElement and Element.Data -> FiberElement.Content

* Add doc comment explaining unowned usage

* Add doc comments explaining implicitly unwrapped optionals

* Attempt to use Swift instead of JS for applying mutations

* Fix issue with not applying updates to DOMFiberElement

* Add comment explaining manual implementation of Hashable for PropertyInfo

* Fix linter issues

* Remove dynamicMember label from subscript

* Re-enable carton test

* Attempt GTK fix

* Add option to disable layout in the FiberReconciler

* Re-enable TokamakDemo with StackReconciler

* Restore CI config

* Restore CI config

* Add file headers and cleanup structure

* Add 'px' to font-size in test outputs

* Remove extra newlines

* Keep track of 'elementChildren' so children are positioned in the correct order

* Use a ViewVisitor to pass the correct View type to the proposeSize function

* Add support for view modifiers

* Add frame modifier to demonstrate modifiers

* Fix TestRenderer

* Remove unused property

* Fix doc comment

* Fix linter issues and refactor slightly

* Fix benchmark builds

* Attempt to fix benchmarks

* Fix sibling layout issues

* Restore original demo

* Support overriding visit function in renderer and _ShapeView drawing

* Support background modifier

* Resolve reconciler issues due to Optionals and elementIndex being set at wrong phase

* Remove Brewfile.lock.json

* Attempt to fix rendering tests

* Formatting nits

* Fix Gradient rendering

Co-authored-by: Max Desiatov <max@desiatov.com>
2022-06-15 15:33:31 +01:00
Carson Katri 6e2ccf71ea
Add configuration options to `App` to choose reconciler (#495)
* Add support for App/Scene

* Refine reconciler configuration options

* Fix tests

* Fix benchmark

* Address review comments

* Rename shouldLayout to useDynamicLayout in remaining file

* Add note to README about switching reconcilers

* Fix typo

* Add App as a type of Fiber content

* Refactor to avoid temporary variable

* Address review comments

* Add [weak self] to createAndBindAlternate closures

* Remove commented lines
2022-06-05 19:24:05 -04:00
Max Desiatov 9db23c9e3f
Tweak formatting rules for attributes (#492)
The abundance of `@_spi(TokamakCore)` makes it harder to parse some of our code visually when skimming. I propose consistently moving attributes on declarations to separate lines. Here's an update to `.swiftformat` config with the new settings applied to the codebase.

* Tweak formatting rules

* Improve readability with newlines

* More newlines to visually separate declarations

* Fix build error caused by merge conflict

Co-authored-by: Carson Katri <Carson.katri@gmail.com>
2022-05-31 08:18:53 +01:00
Carson Katri f4cd4955db
Add support for Fiber label (#493) 2022-05-30 20:15:26 +00:00
Carson Katri 03513dd5b3
Custom Layout Engine for Fiber Reconciler (#472)
* Initial Reconciler using visitor pattern

* Preliminary static HTML renderer using the new reconciler

* Add environment

* Initial DOM renderer

* Nearly-working and simplified reconciler

* Working reconciler for HTML/DOM renderers

* Rename files, and split code across files

* Add some documentation and refinements

* Remove GraphRendererTests

* Initial layout engine (only implemented for the TestRenderer)

* Layout engine for the DOM renderer

* Refined layout pass

* Revise positioning and restoration of position styles on .update

* Re-add Optional.body for StackReconciler-based renderers

* Add text measurement

* Add spacing to StackLayout

* Add benchmarks to compare the stack/fiber reconcilers

* Fix some issues created for the StackReconciler, and add update benchmarks

* Add BenchmarkState.measure to only calculate the time to update

* Fix hang in update shallow benchmark

* Fix build errors

* Address build issues

* Remove File.swift headers

* Rename Element -> FiberElement and Element.Data -> FiberElement.Content

* Add doc comment explaining unowned usage

* Add doc comments explaining implicitly unwrapped optionals

* Attempt to use Swift instead of JS for applying mutations

* Fix issue with not applying updates to DOMFiberElement

* Add comment explaining manual implementation of Hashable for PropertyInfo

* Fix linter issues

* Remove dynamicMember label from subscript

* Re-enable carton test

* Attempt GTK fix

* Add option to disable layout in the FiberReconciler

* Re-enable TokamakDemo with StackReconciler

* Restore CI config

* Restore CI config

* Add file headers and cleanup structure

* Add 'px' to font-size in test outputs

* Remove extra newlines

* Keep track of 'elementChildren' so children are positioned in the correct order

* Use a ViewVisitor to pass the correct View type to the proposeSize function

* Add support for view modifiers

* Add frame modifier to demonstrate modifiers

* Fix TestRenderer

* Remove unused property

* Fix doc comment

* Fix linter issues and refactor slightly

* Fix benchmark builds

* Attempt to fix benchmarks

* Fix sibling layout issues

* Restore original demo

* Address review comments

* Remove maxAxis and fitAxis properties

* Use switch instead of ternary operators

* Add more documentation to layout steps

* Resolve reconciler issue due to alternate child not being cleared/released

* Apply suggestions from code review

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

* Reuse Text resolution code.

* Add more documentation

* Fix typo

* Use structs for LayoutComputers

* Update AlignmentID demo

* Fix weird formatting

Co-authored-by: Max Desiatov <max@desiatov.com>
2022-05-30 15:49:26 -04:00
Carson Katri 355c880a1d
Support `foregroundColor` for `TextField` (#453)
* Support adjusting TextField foregroundColor in TokamakDOM

* Simplify implementation of foregroundColor
2022-05-28 14:46:37 -04:00
Max Desiatov c0c4534352
Clarify testing commands in `CONTRIBUTING.md` (#488)
This should help new contributors to run the test suite locally.
2022-05-24 15:42:31 +01:00
Max Desiatov a604ef5269
Revert "Add html5 doctype to static renderer (#486)" (#487)
* Revert "Add html5 doctype to static renderer (#486)"

This reverts commit 3081f5521a which causes failing layout snapshots we've recently turned back on in https://github.com/TokamakUI/Tokamak/pull/484.

* Fix newlines inconsistency
2022-05-24 10:59:21 +01:00
Andrew Barba 3081f5521a
Add html5 doctype to static renderer (#486)
- Add `<!DOCTYPE html>` to the top of static rendered pages
2022-05-24 10:08:08 +01:00
ezraberch 2e7f561276
Reenable macOS CI builds, using macOS 12 and Xcode 13.4 (#484) 2022-05-24 05:07:22 -04:00
Andrew Barba 2ba548810c
Support meta tags in StaticHTMLRenderer (#483)
This PR adds the ability to control `<head>` tags using a new `HTMLTitle` view and `HTMLMeta` view. Taking inspiration from Next.js `<NextHead>`, you can use these views anywhere in your view hierarchy and they will be hoisted to the top `<head>` section of the html.

Use as a view:

```swift
var body: some View {
  VStack {
    ...
    HTMLTitle("Hello, Tokamak")
    HTMLMeta(charset: "utf-8")
    ...
  }
}
```

Use as a view modifier:

```swift
var body: some View {
  VStack {
    ...
  }
  .htmlTitle("Hello, Tokamak")
  .htmlMeta(charset: "utf-8")
}
```

And the resulting html (no matter where these are used in your view hierarchy):

```html
<html>
  <head>
    <title>Hello, Tokamak</title>
    <meta charset="utf-8">
  </head>
  <body>
    ...
  </body>
</html>
```
2022-05-23 20:03:28 +00:00
Carson Katri 8177fc8cae
Experimental "React Fiber"-like Reconciler (#471)
* Initial Reconciler using visitor pattern

* Preliminary static HTML renderer using the new reconciler

* Add environment

* Initial DOM renderer

* Nearly-working and simplified reconciler

* Working reconciler for HTML/DOM renderers

* Rename files, and split code across files

* Add some documentation and refinements

* Remove GraphRendererTests

* Re-add Optional.body for StackReconciler-based renderers

* Add benchmarks to compare the stack/fiber reconcilers

* Fix some issues created for the StackReconciler, and add update benchmarks

* Add BenchmarkState.measure to only calculate the time to update

* Fix hang in update shallow benchmark

* Fix build errors

* Address build issues

* Remove File.swift headers

* Rename Element -> FiberElement and Element.Data -> FiberElement.Content

* Add doc comment explaining unowned usage

* Add doc comments explaining implicitly unwrapped optionals

* Attempt to use Swift instead of JS for applying mutations

* Fix issue with not applying updates to DOMFiberElement

* Add comment explaining manual implementation of Hashable for PropertyInfo

* Fix linter issues

* Remove dynamicMember label from subscript

* Re-enable carton test

* Re-enable TokamakDemo with StackReconciler

Co-authored-by: Max Desiatov <max@desiatov.com>
2022-05-23 12:14:16 -04:00
Max Desiatov a41ac37500
Update `carton` version in "Requirements" section 2022-05-20 14:05:00 +01:00
Max Desiatov 5b7e7058e8 Bump version to 0.10.1, update `CHANGELOG.md` 2022-05-20 13:48:32 +01:00
Max Desiatov 337b80a4c4
Update JSKit dependency (#482)
* Update JSKit dependency

* Fix deprecations in `Package.swift`

* Use `main` branch of JSKit

* Update JavaScriptKit dependency to stable version
2022-05-19 14:53:48 +01:00
Max Desiatov 528fe056e0
Explicitly mention `carton` version in "Requirements" (#481)
* Explicitly mention `carton` version in "Requirements"

This makes the version number of `carton` required for successful builds more explicit.

* Update README.md

Co-authored-by: Jed Fox <git@jedfox.com>
2022-05-10 15:41:05 +01:00
Max Desiatov 39d37a96c8
Use stable `v5.6` version of `swiftwasm-action` (#477)
After `carton` 0.14.0 was tagged, I've updated `swiftwasm-action` to use that latest release. With that, corresponding `v5.6` was tagged, which I propose to use in `ci.yml` instead of the `main` branch.
2022-05-02 22:07:17 +01:00
Max Desiatov 6905fdff19
Bump version to 0.10.0, update `CHANGELOG.md` (#476)
I'd be happy to include #471 as well, but I personally prefer rolling out big changes in stages. #471 deserves its own release, while in this release the only meaningful change is the Swift version requirement and JSKit/`carton` dependencies bump.
2022-04-09 12:55:30 +01:00
Max Desiatov fd64eafde8
Build and test with SwiftWasm 5.6 on CI (#475)
Had to drop support for Swift 5.4/5.5 and macOS 5.6 jobs, see https://github.com/TokamakUI/Tokamak/pull/475#issuecomment-1092662828 for more details.

Linux builds and `codecov` job were updated to use nightly Swift, which have crashes reproducible in 5.6.0 release fixed.

Also applied a few formatting changes with the latest SwiftFormat.
2022-04-08 21:36:52 +01:00
Max Desiatov eef6bb2da3
Update "Contributing" section in `README.md` 2022-02-21 15:51:47 +00:00
Max Desiatov 1952170ce8
Update "Contributing" section of `README.md` 2022-02-21 15:50:06 +00:00
Max Desiatov 3c649d5ead
Update CHANGELOG.md 2022-02-16 10:41:23 +00:00
yonihemi 12606a809e
Update JavascriptKit (#468)
* Bump JavaScriptKit dependency to 0.12.0.

* Update CHANGELOG.md for 0.9.1 release.

* Fix access to `hash` property

(now that JSObject conforms to Hashable it has a Swift hash property which overrides callAsFunction)

* Update CHANGELOG.md
2022-02-16 10:41:05 +00:00
Vincent Esche a9addc8cb1
Fix `rootEnvironment` not merged with `.defaultEnvironment` (#461)
* Make actual use of `rootEnvironment` passed into functions, falling back to `.defaultEnvironment`

* Add `.merge(_:)`/`.merging(_:)` to `EnvironmentValues`

* Merge `.defaultEnvironment` with `rootEnvironment`

* Add `@_spi(TokamakCore)` protection for `EnvironmentValues.merge(_:)`/`.merging(_:)`
2022-01-03 08:13:14 -05:00
Vincent Esche 077c0cdfcb
Fix typos (#462) 2021-12-31 18:07:30 +00:00
Max Desiatov 5c3bc9d783
Build and test with SwiftWasm 5.5 on CI (#460)
Configuration for simultaneous builds with SwiftWasm 5.4 and 5.5 can't be specified more succinctly due to https://github.com/swiftwasm/swiftwasm-action/issues/3. I had to create almost duplicate job descriptions because of that.
2021-12-21 12:52:50 +01:00
Max Desiatov d2d79c2bbf
Add `DynamicHTML` example code to `README.md` (#459)
This should help our users to get started with `DynamicHTML`.
2021-12-13 18:00:43 +01:00
Max Desiatov 32616fe9d4
Update `CHANGELOG.md` for 0.9.0 release (#458) 2021-11-26 18:06:05 +01:00
Max Desiatov cbfdc34793
Update for JSKit 0.11.1, add async `task` modifier (#457)
I've also moved sources in `TokamakDemo` directory into their respective subdirectories for easier navigation.

* Update for JSKit 0.11.0, add async `task` modifier

* Add back new file locations to `NativeDemo`

* Add compiler `#if` check to `TaskDemo`

* Update to JavaScriptKit 0.11.1

* Restrict `TaskDemo` with `compiler(>=5.5)` check

* Replace `compiler` with `swift` in some places

* Revert "Replace `compiler` with `swift` in some places"

This reverts commit 534784ca7b.

* Use Xcode 13.2 on GitHub Actions hosts

* Find `TokamakPackageTests` in the build directory

* Fix macOS tests bundle path

* Make `task` modifier available only on macOS Monterey

* Revert "Use Xcode 13.2 on GitHub Actions hosts"

This reverts commit 63d044f2d5.

* Revert "Fix macOS tests bundle path"

This reverts commit 3ccbc98a2d.

* Revert "Find `TokamakPackageTests` in the build directory"

This reverts commit 68c845bc19.

* Use `canImport(Concurrency)` as an ultimate check

* Use `compiler(>=5.5) && canImport(Concurrency)`

* Clarify new browser version requirements in `README.md`

* Account for `_Concurrency` naming

* Update `README.md`

* Update README.md

Co-authored-by: ezraberch <49635435+ezraberch@users.noreply.github.com>
2021-11-23 15:31:28 +01:00
Max Desiatov a5a05b4826
Mark Xcode 13.1 as unsupported in `README.md` 2021-11-12 12:34:23 +01:00
Max Desiatov 2ad85b329d
Switch to Xcode 13.0 in `gtk_macos_build` job (#454) 2021-10-23 21:26:39 +01:00
Max Desiatov f07b9fa883
Link to `CONTRIBUTING.md` from `README.md` 2021-10-01 12:11:24 +01:00
Max Desiatov dfc79e4148
Create CONTRIBUTING.md 2021-10-01 12:11:00 +01:00
Carson Katri 005996262a
Add Canvas and TimelineView to DOM renderer (#449)
* Add initial implementations of Canvas and TimelineView

* Add CanvasDemo

* Add the demo to the native project

* Use Xcode 13.0 for macOS builds

* Disable macOS builds until Monterey is available

* Mark CanvasDemo as iOS 15/macOS 12 only, fix LinkButtonStyle reference on iOS

* Add _VariadicView and symbol rendering

* Fix linter warnings

* Add image support

* Revise AnimationTimelineSchedule and requestAnimationFrame cancellation

* Fix pausing of animated TimelineView in TokamakDOM

Co-authored-by: Max Desiatov <max@desiatov.com>
2021-09-28 10:27:35 -04:00
Adam Gastineau da66063918
Initial implementation of `onHover` (#448)
Adds a basic implementation of action modifiers, allowing for dynamic event handling. For testing, adds a trivial `onHover` example.
2021-09-20 16:13:30 +01:00