Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: d36b858cb4e83f4a7be9bf86ef697e3ddbdf82f4
      
https://github.com/WebKit/WebKit/commit/d36b858cb4e83f4a7be9bf86ef697e3ddbdf82f4
  Author: Richard Robinson <[email protected]>
  Date:   2025-02-28 (Fri, 28 Feb 2025)

  Changed paths:
    M Source/WebKit/_WebKit_SwiftUI/CocoaWebViewAdapter.swift
    M Source/WebKit/_WebKit_SwiftUI/Foundation+Extras.swift
    M Source/WebKit/_WebKit_SwiftUI/View+WebViewModifiers.swift
    M Source/WebKit/_WebKit_SwiftUI/ViewModifierContexts.swift

  Log Message:
  -----------
  [SwiftUI] When using the `webViewOnScrollGeometryChange` view modifier, the 
affected WebView is redrawn with each scroll event
https://bugs.webkit.org/show_bug.cgi?id=288645
rdar://145688135

Reviewed by Aditya Keerthi.

SwiftUI layout results in the environment being re-evaluated to see if any 
values differ. In the case of
`webViewOnScrollGeometryChange`, this means that a new 
`OnScrollGeometryChangeContext` was created each time and the environment
updated.

When the environment is updated, SwiftUI calls the `update{UI/NS}View}` 
function of the view representable, and redraws the view.
As a result, each time a scroll event happens, all the logic in the update 
function was being unnecessarily invoked, and the view
was unnecessarily redrawn.

To fix this, ensure that only ever one `OnScrollGeometryChangeContext` is in 
the environment. The logic the client uses in the view
modifier is encapsulated inside an internal dictionary in the context. This is 
needed to ensure that if the view modifier is used
multiple times, that each transform/action is stored individually instead of 
replaced. This dictioanry is keyed by `Namespace` so that
if either of the closures change within the _same_ view modifier application, 
they are simply updated instead of a new change being added.

* Source/WebKit/_WebKit_SwiftUI/CocoaWebViewAdapter.swift:
(CocoaWebViewAdapter.geometryDidChange(_:)):
* Source/WebKit/_WebKit_SwiftUI/Foundation+Extras.swift:
* Source/WebKit/_WebKit_SwiftUI/View+WebViewModifiers.swift:
(OnScrollGeometryChangeModifier.body(_:)):
(EnvironmentValues.webViewOnScrollGeometryChange): Deleted.
* Source/WebKit/_WebKit_SwiftUI/ViewModifierContexts.swift:
(Change.transform):
(Change.action):
(changes):
(apply(from:to:)):

Canonical link: https://commits.webkit.org/291350@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to