Skip to content

Commit

Permalink
Merge pull request #633 from PravinPK/assurance
Browse files Browse the repository at this point in the history
[MOB-14384] - API to modify Floating button image
  • Loading branch information
PravinPK authored May 26, 2021
2 parents 1599c5e + 78a1a26 commit fbf5259
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions AEPServices/Sources/ui/floating/FloatingButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public class FloatingButton: NSObject, FloatingButtonPresentable {
}
}

public func setButtonImage(imageData: Data) {
let image = UIImage(data: imageData)
DispatchQueue.main.async {
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

0 comments on commit fbf5259

Please sign in to comment.