RxSwiftCommunity / Action

Abstracts actions to be performed in RxSwift.
MIT License
875 stars 150 forks source link

UIRefreshControl being displayed before view appears #239

Open tcezario opened 2 years ago

tcezario commented 2 years ago

Hi, I've been trying to implement a UIRefreshControl and bind it to an Action:

refreshControl.rx.bind(to: viewModel.action, inputTransform: { _ in })

This is being done in the init of the view and before the view appears the action method is executed to populate some info. The issue is that whenever this screen is opened the refresh control is shown at the top before disappearing after the action finishes executing. This only happens when the view is instantiated and displayed, navigating back to it doesn't trigger this behavior. Executing on viewDidAppear also doesn't give this issue.

override public func viewWillAppear(_ animated: Bool) {
        self.viewModel.action.execute()
        super.viewWillAppear(animated)
    }

Declaration of the viewModel with the action:

let action: Action<Void, ServiceResponse>

...

public init(...) {
        ...
        getCartAction = Action {
            repository.getInfo()
                .asObservable()
        }
       ...
}

This is happening on both iPhone and Simulator.