Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keep while loading when no image #747

Merged
merged 2 commits into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/ImageView+Kingfisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extension Kingfisher where Base: ImageView {

var options = KingfisherManager.shared.defaultOptions + (options ?? KingfisherEmptyOptionsInfo)

if !options.keepCurrentImageWhileLoading {
if !options.keepCurrentImageWhileLoading || base.image == nil {
base.image = placeholder
}

Expand Down
23 changes: 23 additions & 0 deletions Tests/KingfisherTests/ImageViewExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,29 @@ class ImageViewExtensionTests: XCTestCase {
waitForExpectations(timeout: 5, handler: nil)
}

func testSettingImageKeepingRespectingPlaceholder() {
let expectation = self.expectation(description: "wait for downloading image")
let URLString = testKeys[0]
_ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
let url = URL(string: URLString)!

// While current image is nil, set placeholder
imageView.kf.setImage(with: url, placeholder: testImage, options: [.keepCurrentImageWhileLoading])
XCTAssertNotNil(imageView.image)
XCTAssertEqual(testImage, imageView.image)

// While current image is not nil, keep it
let anotherImage = Image(data: testImageJEPGData)
imageView.image = anotherImage
imageView.kf.setImage(with: url, placeholder: testImage, options: [.keepCurrentImageWhileLoading])
XCTAssertNotNil(imageView.image)
XCTAssertEqual(anotherImage, imageView.image)

// Wait request finished. Ensure tests timing order.
delay(0.1, block: expectation.fulfill)
waitForExpectations(timeout: 5, handler: nil)
}

func testSetGIFImageOnlyFirstFrameThenFullFrames() {
let expectation = self.expectation(description: "wait for downloading image")

Expand Down