Skip to content

Commit

Permalink
Merge pull request #174 from RxSwiftCommunity/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
twittemb authored May 22, 2021
2 parents 0a96fa2 + 75ca959 commit e85a544
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
swift-version: ['5.3']
steps:
- name: Install Swift
uses: YOCKOW/Action-setup-swift@master
uses: YOCKOW/Action-setup-swift@main
with:
swift-version: ${{ matrix.swift-version }}
- uses: actions/checkout@master
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
** Version 2.12.2 **:

- ensure the navigate function is called on the main thread (regression introduced in 2.12.1)

** Version 2.12.1 **:

- fix a possible memory leak when the Coordinator's lifecycle was unexpectedly longer than the flow ones (thanks to @asiliuk)
Expand Down
2 changes: 1 addition & 1 deletion RxFlow.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "RxFlow"
s.version = "2.12.1"
s.version = "2.12.2"
s.swift_version = '5.3'
s.summary = "RxFlow is a navigation framework for iOS applications, based on a Reactive Coordinator pattern."

Expand Down
4 changes: 2 additions & 2 deletions RxFlow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.12.1;
MARKETING_VERSION = 2.12.2;
PRODUCT_BUNDLE_IDENTIFIER = io.warpfactor.RxFlow;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -639,7 +639,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.12.1;
MARKETING_VERSION = 2.12.2;
PRODUCT_BUNDLE_IDENTIFIER = io.warpfactor.RxFlow;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
7 changes: 5 additions & 2 deletions RxFlow/FlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public final class FlowCoordinator: NSObject {
self?.childFlowCoordinators.removeAll()
self?.parentFlowCoordinator?.childFlowCoordinators.removeValue(forKey: self?.identifier ?? "")
})
.flatMapLatest { flow.adapt(step: $0) }
.asSignal(onErrorJustReturn: NoneStep())
.flatMapLatest { flow.adapt(step: $0).asSignal(onErrorJustReturn: NoneStep()) }
.do(onNext: { [weak self] in self?.willNavigateRelay.accept((flow, $0)) })
.map { return (flowContributors: flow.navigate(to: $0), step: $0) }
.do(onNext: { [weak self] in self?.didNavigateRelay.accept((flow, $0.step)) })
Expand All @@ -77,8 +78,9 @@ public final class FlowCoordinator: NSObject {
.do(onNext: { [weak self] presentableAndSteppers in
self?.setReadiness(for: flow, basedOn: presentableAndSteppers.map { $0.presentable })
})
// transforms a FlowContributors in a sequence of individual FlowContributor

.flatMap { Signal.from($0) }
// transforms a FlowContributors in a sequence of individual FlowContributor
// the FlowContributor is related to a new Flow, we coordinate this new Flow
.do(onNext: { [weak self] presentableAndStepper in
if let childFlow = presentableAndStepper.presentable as? Flow {
Expand All @@ -96,6 +98,7 @@ public final class FlowCoordinator: NSObject {
.flatMap { [weak self] in
self?.steps(from: $0, within: flow, allowStepWhenDismissed: allowStepWhenDismissed) ?? Signal.empty()
}
.asObservable()
.take(until: allowStepWhenDismissed ? .empty() : flow.rxDismissed.asObservable())
.asSignal(onErrorJustReturn: NoneStep())
.emit(to: self.stepsRelay)
Expand Down
46 changes: 46 additions & 0 deletions RxFlowTests/FlowCoordinatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#if canImport(UIKit)

import Dispatch
@testable import RxFlow
import XCTest
import RxBlocking
Expand Down Expand Up @@ -367,6 +368,51 @@ final class FlowCoordinatorTests: XCTestCase {

XCTAssertNil(leakingFlowReference)
}

func testNavigate_executes_on_mainThread() {
class ThreadRecorderFlow: Flow {
let rootViewController = UINavigationController()
var root: Presentable {
return rootViewController
}

var recordedThreadName: String?

func adapt(step: Step) -> Single<Step> {
return Single.just(step).observe(on: SerialDispatchQueueScheduler(internalSerialQueueName: UUID().uuidString))
}

func navigate(to step: Step) -> FlowContributors {
self.recordedThreadName = DispatchQueue.currentLabel
return .none
}
}

let exp = expectation(description: "Navigates on main thread")

// Given: a Flow that records its navigation thread (and adapt on a background thread)
let recorderFlow = ThreadRecorderFlow()
let sut = FlowCoordinator()

Flows.use(recorderFlow, when: .ready) { (_) in
exp.fulfill()
}

// When: coordinating that flow
sut.coordinate(flow: recorderFlow,
with: OneStepper(withSingleStep: TestSteps.one))

waitForExpectations(timeout: 0.5)

// Then: the flow navigates on the main thread
XCTAssertEqual(recorderFlow.recordedThreadName, "com.apple.main-thread")
}
}

extension DispatchQueue {
class var currentLabel: String {
return String(validatingUTF8: __dispatch_queue_get_label(nil))!
}
}

#endif
19 changes: 19 additions & 0 deletions xcarthage-archive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# carthage-update.sh
# Usage example: ./carthage-archive.sh

set -euo pipefail

xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX)
trap 'rm -f "$xcconfig"' INT TERM HUP EXIT

# For Xcode 12 make sure EXCLUDED_ARCHS is set to arm architectures otherwise
# the build will fail on lipo due to duplicate architectures.

CURRENT_XCODE_VERSION=$(xcodebuild -version | grep "Build version" | cut -d' ' -f3)
echo "EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_$CURRENT_XCODE_VERSION = arm64 arm64e armv7 armv7s armv6 armv8" >> $xcconfig

echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200 = $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_$(XCODE_PRODUCT_BUILD_VERSION))' >> $xcconfig
echo 'EXCLUDED_ARCHS = $(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT)__XCODE_$(XCODE_VERSION_MAJOR))' >> $xcconfig

export XCODE_XCCONFIG_FILE="$xcconfig"
carthage build --archive --cache-builds
2 changes: 1 addition & 1 deletion xcarthage-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x8
echo 'EXCLUDED_ARCHS = $(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT)__XCODE_$(XCODE_VERSION_MAJOR))' >> $xcconfig

export XCODE_XCCONFIG_FILE="$xcconfig"
carthage bootstrap "$@"
carthage bootstrap "$@" --cache-builds

0 comments on commit e85a544

Please sign in to comment.