Skip to content

Commit

Permalink
Rename viewEnvironment to environment
Browse files Browse the repository at this point in the history
  • Loading branch information
n8chur committed Mar 30, 2023
1 parent 3391f7a commit 11998ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions ViewEnvironmentUI/Sources/ViewEnvironmentPropagating.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public protocol ViewEnvironmentPropagating {
/// `layoutSubviews()` respectively.
///
@_spi(ViewEnvironmentWiring)
var viewEnvironment: ViewEnvironment { get }
var environment: ViewEnvironment { get }
}

extension ViewEnvironmentPropagating {
Expand Down Expand Up @@ -110,20 +110,20 @@ extension ViewEnvironmentPropagating {
/// ``ViewEnvironmentObserving/applyEnvironmentIfNeeded()-8gr5k`` in `viewWillLayoutSubviews()` and
/// `layoutSubviews()` respectively.
///
public var viewEnvironment: ViewEnvironment {
public var environment: ViewEnvironment {
_defaultViewEnvironment
}

/// The default `ViewEnvironment` returned by ``viewEnvironment-1p2gj``.
/// The default `ViewEnvironment` returned by ``environment``.
///
/// The environment is constructed by recursively walking to the root of the propagation path
/// and then applying all customizations on the way back down.
///
/// You should only need to access this value if you are overriding ``viewEnvironment-1p2gj``
/// You should only need to access this value if you are overriding ``environment``
/// and want to conditionally return the default.
@_spi(ViewEnvironmentWiring)
public var _defaultViewEnvironment: ViewEnvironment {
var environment = environmentAncestor?.viewEnvironment
var environment = environmentAncestor?.environment
?? .empty

(self as? ViewEnvironmentCustomizing)?.customize(environment: &environment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension ViewEnvironmentObserving where Self: ViewEnvironmentPropagatingObject

needsEnvironmentUpdate = false

apply(environment: viewEnvironment)
apply(environment: environment)
}
}

Expand Down Expand Up @@ -215,7 +215,7 @@ extension ViewEnvironmentPropagatingObject {
needsEnvironmentUpdate = true

if !needsUpdateObservers.isEmpty {
let environment = viewEnvironment
let environment = self.environment

for observer in needsUpdateObservers.values {
observer(environment)
Expand Down
10 changes: 5 additions & 5 deletions ViewEnvironmentUI/Tests/ViewEnvironmentObservingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class ViewEnvironmentObservingTests: XCTestCase {
container.addChild(child)
child.didMove(toParent: container)

XCTAssertEqual(child.viewEnvironment.testContext.number, 1)
XCTAssertEqual(child.environment.testContext.number, 1)
}

func test_environment_propagation_to_presented() {
Expand All @@ -30,7 +30,7 @@ final class ViewEnvironmentObservingTests: XCTestCase {

container.present(child, animated: false, completion: {})

XCTAssertEqual(child.viewEnvironment.testContext.number, 1)
XCTAssertEqual(child.environment.testContext.number, 1)
}

func test_environment_multiple_overrides_with_root() {
Expand Down Expand Up @@ -67,7 +67,7 @@ final class ViewEnvironmentObservingTests: XCTestCase {
// Mutation by child
expectedContext.number = 2

XCTAssertEqual(child.viewEnvironment.testContext, expectedContext)
XCTAssertEqual(child.environment.testContext, expectedContext)
}

// MARK: - apply(environment:)
Expand Down Expand Up @@ -176,7 +176,7 @@ final class ViewEnvironmentObservingTests: XCTestCase {
let viewController = UIViewController()
viewController.environmentAncestorOverride = { ancestor }

XCTAssertEqual(viewController.viewEnvironment.testContext, expectedTestContext)
XCTAssertEqual(viewController.environment.testContext, expectedTestContext)
}

func test_descendant_customFlow() {
Expand Down Expand Up @@ -229,7 +229,7 @@ final class ViewEnvironmentObservingTests: XCTestCase {
XCTAssertTrue(child.needsEnvironmentUpdate)
XCTAssertTrue(descendant.needsEnvironmentUpdate)

XCTAssertEqual(descendant.viewEnvironment.testContext, expectedContext)
XCTAssertEqual(descendant.environment.testContext, expectedContext)
}

// MARK: - Observations
Expand Down

0 comments on commit 11998ee

Please sign in to comment.