Closed kaich closed 3 years ago
@kaich try setup the binding in cell's init function ?
@wddwycc Yes, I'm binding the cell in the init function init(style: UITableViewCell.CellStyle, reuseIdentifier: String?)
. I think the observer receive the initial value after it displayed.
@kaich Since the signal is emitted asyncronously after the binding, what you mentioned is possbile to happen. I'm thinking about apply a setter before the binding.
@wddwycc Looking forward to your good news.
@kaich I'll take a look this week
Just realized I did some interface design attempts on dev branch before to improve this, but cannot achieve a flexible API at that time.
@wddwycc I spend time to do it like below:
public class ThemeAttribute<U> {
var value: U?
var steam: Observable<U>?
init<Provider: ThemeProvider>(service: ThemeService<Provider>, mapper: @escaping ((Provider.T) -> U)) {
value = mapper(service.attrs)
steam = service.attrStream(mapper)
}
}
extension ThemeService {
func attribute<U>(mapper: @escaping ((Provider.T) -> U)) -> ThemeAttribute<U> {
return ThemeAttribute(service: self, mapper: mapper)
}
}
Then I change all extension like this:
var backgroundColor: Observable<CGColor?>
to var backgroundColor: ThemeAttribute<CGColor?>
.
So I can get the initialized value. If there are any changes in future, I can modify the ThemeAttribute
very easily.
Finally , We can use it like this:
view.theme.backgroundColor = themeService.attribute { $0.backgroundColor }
The codes are not big change. Do you think It's a good idea ? If so, I will change it and create a pull request.
Hope your reply. Thanks.
@kaich looks good to me, please send the PR (๑•̀ㅂ•́)و✧
@kaich
thank you for the PR. I've merged and did some interface adjustment. It's been released in 6.0.0.
When I use the
contentView.theme.backgroundColor = themeService.attrStream { $0.backgroundColor }
to the custom UITableViewCell. It will show the white at first sometimes, then show the theme color.When I set
contentView.backgroundColor = themeService.type.theme.backgroundColor
, it works fine.How to resolve it ?
Wish your reply. Thanks.