Skip to content

Commit

Permalink
fix: fix show not being called from main thread (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
omaralbeik authored May 21, 2021
1 parent c5a6b69 commit 3314384
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Drops.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Drops'
s.version = '1.2.0'
s.version = '1.2.1'
s.summary = 'A µFramework for showing iOS 13 like system alerts'
s.description = <<-DESC
A µFramework for showing alerts like the one used when copying from pasteboard or connecting Apple pencil.
Expand Down
4 changes: 2 additions & 2 deletions Drops.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.2.1;
PRODUCT_BUNDLE_IDENTIFIER = com.omaralbeik.drops;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -803,7 +803,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.2.0;
MARKETING_VERSION = 1.2.1;
PRODUCT_BUNDLE_IDENTIFIER = com.omaralbeik.drops;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ The [Swift Package Manager](https://swift.org/package-manager/) is a tool for ma

```swift
dependencies: [
.package(url: "https://github.com/omaralbeik/Drops.git", from: "1.2.0")
.package(url: "https://github.com/omaralbeik/Drops.git", from: "1.2.1")
]
```

Expand All @@ -119,15 +119,15 @@ $ swift build
To integrate Drops into your Xcode project using [CocoaPods](https://cocoapods.org), specify it in your Podfile:

```rb
pod 'Drops', :git => 'https://github.com/omaralbeik/Drops.git', :tag => '1.2.0'
pod 'Drops', :git => 'https://github.com/omaralbeik/Drops.git', :tag => '1.2.1'
```

### Carthage

To integrate Drops into your Xcode project using [Carthage](https://github.com/Carthage/Carthage), specify it in your Cartfile:

```
github "omaralbeik/Drops" ~> 1.0
github "omaralbeik/Drops" ~> 1.2
```

### Manually
Expand Down
6 changes: 4 additions & 2 deletions Sources/Drops.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public final class Drops {
/// Show a drop.
/// - Parameter drop: `Drop` to show.
public func show(_ drop: Drop) {
let presenter = Presenter(drop: drop, delegate: self)
enqueue(presenter: presenter)
DispatchQueue.main.async {
let presenter = Presenter(drop: drop, delegate: self)
self.enqueue(presenter: presenter)
}
}

/// Hide currently shown drop.
Expand Down
26 changes: 18 additions & 8 deletions Tests/DropsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,20 @@ final class DropsTests: XCTestCase {
func testDropsAreQueued() {
let drops = Drops()
(0..<5)
.map { Drop(title: "\($0)", duration: .seconds(0.1)) }
.map { Drop(title: "\($0)", duration: .seconds(0.5)) }
.forEach(drops.show)

XCTAssertEqual(drops.queue.count, 5-1)
let exp1 = expectation(description: "All Drops are hidden")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
if drops.queue.count == 5-1 {
exp1.fulfill()
}
}

let exp = expectation(description: "All Drops are hidden")
let exp2 = expectation(description: "All Drops are hidden")
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
if drops.queue.isEmpty {
exp.fulfill()
exp2.fulfill()
}
}

Expand All @@ -89,15 +94,20 @@ final class DropsTests: XCTestCase {

func testStaticDropsAreQueued() {
(0..<5)
.map { Drop(title: "\($0)", duration: .seconds(0.1)) }
.map { Drop(title: "\($0)", duration: .seconds(0.5)) }
.forEach(Drops.show)

XCTAssertEqual(Drops.shared.queue.count, 5-1)
let exp1 = expectation(description: "All Drops are hidden")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
if Drops.shared.queue.count == 5-1 {
exp1.fulfill()
}
}

let exp = expectation(description: "All Drops are hidden")
let exp2 = expectation(description: "All Drops are hidden")
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
if Drops.shared.queue.isEmpty {
exp.fulfill()
exp2.fulfill()
}
}

Expand Down

0 comments on commit 3314384

Please sign in to comment.