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

Adjust the image setting method of ImageRow and ButtonRow #32

Merged
merged 2 commits into from
May 27, 2024

Conversation

rakuyoMo
Copy link
Member

@rakuyoMo rakuyoMo commented May 27, 2024

In the past, the image setting logic of ImageRow and ButtonRow was incorrect or too cumbersome.

Taking ImageRow as an example, the call to Content after reconstruction:

ImageRow.groupItem(
    dataID: DefaultDataID.noneProvided,
    content: .init(UIImage(...)),
    style: .init())

ImageRow.groupItem(
    dataID: DefaultDataID.noneProvided,
    content: .init("image-name"), // Equivalent to `UIImage(named: "image-name")`
    style: .init())

There are also some convenience methods provided in FastImageContentProviding:

 ImageRow.groupItem(
    dataID: DefaultDataID.noneProvided,
    content: .sfSymbols(name: ""),
    style: .init())

Alternatively, you can implement your own data provider via the ImageContentProviding protocol:

struct ImagePath: ImageContentProviding {
    let path: URL?

    fileprivate init(path: URL?) {
        self.path = path
    }

    func setForView<V>(_ view: V?) {
        guard let _view = (view as? ImageRow) else { return }

        let source = path.flatMap {
            Source.provider(LocalFileImageDataProvider(fileURL: $0))
        }

        _view.kf.setImage(with: source, placeholder: nil, options: [
            .cacheMemoryOnly,
            .transition(.fade(AnimationDuration.short.rawValue)),
            .processor(
                RoundCornerImageProcessor(
                    cornerRadius: _view.layer.cornerRadius,
                    roundingCorners: [.topLeft, .topRight]
                )
            ),
        ])
    }
}

ButtonRow is the same, but uses ButtonImageContentProviding

@rakuyoMo rakuyoMo merged commit 4080642 into main May 27, 2024
1 check passed
@rakuyoMo rakuyoMo deleted the fix/update-ButtonRow-image branch May 27, 2024 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant