Commit Graph

14 Commits

Author SHA1 Message Date
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
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
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 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
Carson Katri 6792dbb02c
Fix background/overlay layout in DOM/HTML renderers (#429) 2021-07-17 15:45:32 -04:00
Carson Katri 4a7748ad6b
Add `Material` to the HTML renderer (#418) 2021-07-07 18:09:13 -04:00
Carson Katri 54146b8a38
Improve ShapeStyles to match iOS 15+ (#417) 2021-07-07 16:04:26 -04:00
Max Desiatov ae219e947b
Use `CGFloat`, `CGPoint`, `CGRect` from Foundation (#411)
Resolves #404.

This also allows us to write more tests that are source-compatible with SwiftUI.

* Use `CGFloat`, `CGPoint`, `CGRect` from Foundation

* Fix GTK build

* Fix macOS build
2021-06-19 19:29:44 +01:00
Carson Katri 9d347f49f3
Add Preferences (#307)
This adds the `PreferenceKey` protocol and related modifiers.

* Initial PreferenceKey implementation

* Don't send default value to match SwiftUI behavior

* Add CustomDebugStringConvertible conformance to Color

* PR fixes

* Fix onAppear and preference modification calls

* Attempt macOS build fix

* Fix <background/overlay>PreferenceValue

* Implement/revise transformPreference

* Fix linter warnings, apply SwiftFormat

Co-authored-by: Max Desiatov <max@desiatov.com>
2020-12-04 11:19:14 +00:00
Max Desiatov f24a09f006
Apply latest SwiftFormat 2020-11-09 12:27:17 +00:00
Carson Katri c43d2db1b3
Add default dark styles for Views (#241) 2020-08-10 16:05:53 -04: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
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
Carson Katri f9f11a0113
Shape, Path, and some related modifiers (#119)
* Initial Shape support

* Border modifier

* Better demo

* Make Path conform to Shape

* Implement clipShape

* Add shapes/path/shapestyles to progress.md
2020-06-30 15:00:16 -04:00