Skip to content

Commit

Permalink
Merge pull request #210 from wwt/fix-209
Browse files Browse the repository at this point in the history
Fixes an issue where skipping views with a NavigationStack or Modal presentation style didn't work correctly with SwiftUI
  • Loading branch information
Tyler-Keith-Thompson committed Aug 13, 2022
2 parents fc8bc23 + 4d11119 commit 2cebe59
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 48 deletions.
Expand Up @@ -347,7 +347,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = KRX3M99K22;
Expand All @@ -367,7 +367,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = KRX3M99K22;
Expand Down
30 changes: 13 additions & 17 deletions .github/fastlane/Fastfile
Expand Up @@ -35,23 +35,6 @@ platform :ios do
end
end

lane :CLI_test do
Dir.chdir("..") do
setup_ci()
match(
app_identifier: ["WWT.SwiftCurrent-IRGeneratorTests"],
readonly: is_ci,
git_url: "git@github.com:wwt/swiftcurrent-ios-certs-and-profiles.git"
)
xcodebuild(
test: true,
scheme: 'SwiftCurrent_CLI',
workspace: 'SwiftCurrent.xcworkspace',
destination: [ 'platform=macOS' ]
)
end
end

lane :build_swiftpm do
# Confirm Core can build against Swift without any Apple SDK requirements
sh('rm -rf ../../SwiftCurrent.xcworkspace/')
Expand Down Expand Up @@ -144,3 +127,16 @@ platform :ios do
echo(message: "##[set-output name=version;]#{version}")
end
end

platform :mac do
lane :CLI_test do
scan(
code_coverage: true,
scheme: 'SwiftCurrent_CLI',
workspace: '../SwiftCurrent.xcworkspace',
derived_data_path: "~/Library/Developer/Xcode/DerivedData",
result_bundle: true,
destination: "platform=macOS"
)
end
end
21 changes: 13 additions & 8 deletions .github/fastlane/README.md
Expand Up @@ -31,14 +31,6 @@ For _fastlane_ installation instructions, see [Installing _fastlane_](https://do



### ios CLI_test

```sh
[bundle exec] fastlane ios CLI_test
```



### ios build_swiftpm

```sh
Expand Down Expand Up @@ -95,6 +87,19 @@ Release a new version with a minor bump_type

Release a new version with a major bump_type

----


## macOS

### macOS CLI_test

```sh
[bundle exec] fastlane macOS CLI_test
```



----

This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run.
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/CI.yml
Expand Up @@ -44,17 +44,12 @@ jobs:
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
MATCH_DEPLOY_KEY: ${{ secrets.MATCH_DEPLOY_KEY }}
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
MATCH_READONLY: true
steps:
- uses: actions/checkout@v2
- name: Run CLI TESTS
run: |
eval "$(ssh-agent -s)"
ssh-add - <<< "${MATCH_DEPLOY_KEY}"
bundle exec fastlane CLI_test
bundle exec fastlane mac CLI_test
working-directory: ${{ env.working-directory }}

build_for_swift_package_manager:
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/PR_CI.yml
Expand Up @@ -41,17 +41,12 @@ jobs:
env:
working-directory: .github
DEVELOPER_DIR: /Applications/Xcode_13.0.app/Contents/Developer
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
MATCH_DEPLOY_KEY: ${{ secrets.MATCH_DEPLOY_KEY }}
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
MATCH_READONLY: true
steps:
- uses: actions/checkout@v2
- name: Run CLI TESTS
run: |
eval "$(ssh-agent -s)"
ssh-add - <<< "${MATCH_DEPLOY_KEY}"
bundle exec fastlane CLI_test
bundle exec fastlane mac CLI_test
working-directory: ${{ env.working-directory }}

build_for_swift_package_manager:
Expand Down
Expand Up @@ -19,6 +19,7 @@ public protocol _WorkflowItemProtocol: View where FlowRepresentableType: FlowRep
func canDisplay(_ element: AnyWorkflow.Element?) -> Bool
mutating func setElementRef(_ element: AnyWorkflow.Element?)
func modify(workflow: AnyWorkflow)
func didDisplay(_ element: AnyWorkflow.Element?) -> Bool
}

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
Expand All @@ -42,4 +43,6 @@ extension Never: _WorkflowItemProtocol {
public func canDisplay(_ element: AnyWorkflow.Element?) -> Bool { false }
/// :nodoc: Protocol requirement.
public func modify(workflow: AnyWorkflow) { }
/// :nodoc: Protocol requirement.
public func didDisplay(_ element: AnyWorkflow.Element?) -> Bool { false }
}
Expand Up @@ -5,8 +5,6 @@
// Created by Tyler Thompson on 2/21/22.
// Copyright © 2022 WWT and Tyler Thompson. All rights reserved.
// swiftlint:disable line_length
// swiftlint:disable operator_usage_whitespace
// swiftlint BUG: https://github.com/realm/SwiftLint/issues/3668

import Foundation

Expand Down
14 changes: 14 additions & 0 deletions Sources/SwiftCurrent_SwiftUI/TypeErased/AnyWorkflowItem.swift
Expand Up @@ -45,6 +45,11 @@ extension AnyWorkflowItem {
public func modify(workflow: AnyWorkflow) {
storage.modify(workflow: workflow)
}

/// :nodoc: Protocol requirement.
public func didDisplay(_ element: AnyWorkflow.Element?) -> Bool {
storage.didDisplay(element)
}
}

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
Expand All @@ -59,6 +64,11 @@ fileprivate class AnyWorkflowItemStorageBase {
fatalError("AnyWorkflowItemStorageBase called directly, only available internally so something has gone VERY wrong.")
}

// swiftlint:disable:next unavailable_function
func didDisplay(_ element: AnyWorkflow.Element?) -> Bool {
fatalError("AnyWorkflowItemStorageBase called directly, only available internally so something has gone VERY wrong.")
}

var workflowLaunchStyle: LaunchStyle.SwiftUI.PresentationType {
fatalError("AnyWorkflowItemStorageBase called directly, only available internally so something has gone VERY wrong.")
}
Expand All @@ -79,6 +89,10 @@ fileprivate final class AnyWorkflowItemStorage<Wrapped: _WorkflowItemProtocol>:
holder.modify(workflow: workflow)
}

override func didDisplay(_ element: AnyWorkflow.Element?) -> Bool {
holder.didDisplay(element)
}

override var workflowLaunchStyle: LaunchStyle.SwiftUI.PresentationType {
holder.workflowLaunchStyle
}
Expand Down
12 changes: 12 additions & 0 deletions Sources/SwiftCurrent_SwiftUI/Views/EitherWorkflowItem.swift
Expand Up @@ -34,6 +34,13 @@ public struct EitherWorkflowItem<W0: _WorkflowItemProtocol, W1: _WorkflowItemPro
}
}

func didDisplay(_ element: AnyWorkflow.Element?) -> Bool {
switch self {
case .first(let first): return first.didDisplay(element)
case .second(let second): return second.didDisplay(element)
}
}

case first(First)
case second(Second)

Expand All @@ -59,6 +66,11 @@ public struct EitherWorkflowItem<W0: _WorkflowItemProtocol, W1: _WorkflowItemPro
public func canDisplay(_ element: AnyWorkflow.Element?) -> Bool {
content.canDisplay(element)
}

/// :nodoc: Protocol requirement.
public func didDisplay(_ element: AnyWorkflow.Element?) -> Bool {
content.didDisplay(element)
}
}

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
Expand Down
5 changes: 5 additions & 0 deletions Sources/SwiftCurrent_SwiftUI/Views/OptionalWorkflowItem.swift
Expand Up @@ -30,6 +30,11 @@ public struct OptionalWorkflowItem<WI: _WorkflowItemProtocol>: View, _WorkflowIt
public func canDisplay(_ element: AnyWorkflow.Element?) -> Bool {
content?.canDisplay(element) ?? false
}

/// :nodoc: Protocol requirement.
public func didDisplay(_ element: AnyWorkflow.Element?) -> Bool {
content?.didDisplay(element) ?? false
}
}

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftCurrent_SwiftUI/Views/WorkflowGroup.swift
Expand Up @@ -26,6 +26,10 @@ public struct WorkflowGroup<WI: _WorkflowItemProtocol>: View, _WorkflowItemProto
public func canDisplay(_ element: AnyWorkflow.Element?) -> Bool {
content.canDisplay(element)
}

public func didDisplay(_ element: AnyWorkflow.Element?) -> Bool {
content.didDisplay(element)
}
}

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftCurrent_SwiftUI/Views/WorkflowItem.swift
Expand Up @@ -57,6 +57,10 @@ public struct WorkflowItem<FlowRepresentableType: FlowRepresentable & View, Cont
(element?.extractErasedView() as? Content != nil) && (elementRef == nil || elementRef === element)
}

public func didDisplay(_ element: AnyWorkflow.Element?) -> Bool {
(elementRef != nil || elementRef === element)
}

public mutating func setElementRef(_ element: AnyWorkflow.Element?) {
if canDisplay(element) {
elementRef = element
Expand Down
12 changes: 9 additions & 3 deletions Sources/SwiftCurrent_SwiftUI/Views/WorkflowItemWrapper.swift
Expand Up @@ -35,11 +35,13 @@ public struct WorkflowItemWrapper<WI: _WorkflowItemProtocol, Wrapped: _WorkflowI

public var body: some View {
ViewBuilder {
if launchStyle == .navigationLink {
let canDisplay = content.canDisplay(model.body)
let shouldDisplayContent = canDisplay || content.didDisplay(model.body)
if launchStyle == .navigationLink, shouldDisplayContent {
content.navLink(to: nextView, isActive: $isActive)
} else if case .modal(let modalStyle) = wrapped?.workflowLaunchStyle {
} else if case .modal(let modalStyle) = wrapped?.workflowLaunchStyle, shouldDisplayContent {
content.modal(isPresented: $isActive, style: modalStyle, destination: nextView)
} else if launchStyle != .navigationLink, content.canDisplay(model.body) {
} else if canDisplay {
content
} else {
nextView
Expand Down Expand Up @@ -84,6 +86,10 @@ public struct WorkflowItemWrapper<WI: _WorkflowItemProtocol, Wrapped: _WorkflowI
content.canDisplay(element) || wrapped?.canDisplay(element) == true
}

public func didDisplay(_ element: AnyWorkflow.Element?) -> Bool {
content.didDisplay(element) || wrapped?.canDisplay(element) == true
}

public func modify(workflow: AnyWorkflow) {
content.modify(workflow: workflow)
wrapped?.modify(workflow: workflow)
Expand Down
Expand Up @@ -2284,7 +2284,7 @@ final class GenericConstraintTests: XCTestCase, View {
}

@available(iOS 15, macOS 11, tvOS 14.0, watchOS 7.0, *)
final class ThenProceedOnAppTests: XCTestCase, App {
final class ThenProceedOnAppTests: XCTestCase {
func testThenProceedFunctionsAsExpectedOnApp() async throws {
struct FR0: PassthroughFlowRepresentable, View, Inspectable {
var _workflowPointer: AnyFlowRepresentable?
Expand Down
Expand Up @@ -15,7 +15,7 @@ import SwiftCurrent
import SwiftCurrent_Testing

@available(iOS 15.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
final class SwiftCurrent_SwiftUIConsumerTests: XCTestCase, App {
final class SwiftCurrent_SwiftUIConsumerTests: XCTestCase {
func testWorkflowCanBeFollowed() async throws {
struct FR1: View, FlowRepresentable, Inspectable {
var _workflowPointer: AnyFlowRepresentable?
Expand Down
Expand Up @@ -14,7 +14,7 @@ import SwiftCurrent
@testable import SwiftCurrent_SwiftUI // testable sadly needed for inspection.inspect to work

@available(iOS 15.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
final class SwiftCurrent_SwiftUI_WorkflowBuilderArityTests: XCTestCase, App {
final class SwiftCurrent_SwiftUI_WorkflowBuilderArityTests: XCTestCase {
func testArity1() async throws {
struct FR1: View, FlowRepresentable, Inspectable {
var _workflowPointer: AnyFlowRepresentable?
Expand Down
Expand Up @@ -14,7 +14,7 @@ import SwiftCurrent
@testable import SwiftCurrent_SwiftUI // testable sadly needed for inspection.inspect to work

@available(iOS 15.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
final class SwiftCurrent_SwiftUI_WorkflowBuilderTests: XCTestCase, App {
final class SwiftCurrent_SwiftUI_WorkflowBuilderTests: XCTestCase {
func testWorkflowCanBeFollowed() async throws {
struct FR1: View, FlowRepresentable, Inspectable {
var _workflowPointer: AnyFlowRepresentable?
Expand Down

0 comments on commit 2cebe59

Please sign in to comment.