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

[MOB-14384] - API to modify Floating button image #633

Merged
merged 3 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions AEPServices/Sources/ui/floating/FloatingButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ public class FloatingButton: NSObject, FloatingButtonPresentable {
}
}

/// Set the Image for the floating button.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal opinion here: But I don't think it is necessary to include doc comments on functions where the doc comment is defined in the protocol for the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed it was repetitive

/// The size of the floating button is 60x60 (width x height), provide the image data accordingly
/// - Parameters:
/// - imageData : The `Data` representation of a UIImage
public func setButtonImage(imageData: Data) {
DispatchQueue.main.async {
let image = UIImage(data: imageData)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we can't just take in a UIImage instead of Data? If not, I wonder if creating the UIImage off the main thread may be slightly more responsible.

Copy link
Contributor Author

@PravinPK PravinPK May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taking in Data is more generic than UIImage. Given that UIImage is available in TVOS and iOS and not in watchOS (WKInterfaceImage)... Let me know otherwise (if there is any benefits passing UIImage)

+1 for moving UIImage creation outside the main thread

self.buttonImageView?.image = image
}
}

private func initFloatingButton() -> Bool {
guard let newFrame: CGRect = getImageFrame() else {
Log.debug(label: LOG_PREFIX, "Floating button couldn't be displayed, failed to create a new frame.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ import Foundation
/// Represents a FloatingButton UI element which is both `Showable` and `Dismissible`
///
@objc(AEPFloatingButtonPresentable)
public protocol FloatingButtonPresentable: Showable, Dismissible {}
public protocol FloatingButtonPresentable: Showable, Dismissible {

/// Set the Image for the floating button.
/// The size of the floating button is 60x60 (width x height), provide the image data accordingly
/// - Parameters:
/// - imageData : The `Data` representation of a UIImage
func setButtonImage(imageData: Data)
}
5 changes: 5 additions & 0 deletions AEPServices/Tests/services/FloatingButtonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class FloatingButtonTests : XCTestCase {
XCTAssertNoThrow(floatingButton?.dismiss())
}

func test_setButtonImage() {
floatingButton = FloatingButton(listener: mockListener)
XCTAssertNoThrow(floatingButton?.setButtonImage(imageData: Data()))
}

class MockListener: FloatingButtonDelegate {
func onShow() {}
func onDismiss() {}
Expand Down