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 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
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