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

scrollView.contentInset is reverted back after changing it in visibleHeight callback #94

Open
M0rtyMerr opened this issue Jul 16, 2019 · 0 comments

Comments

@M0rtyMerr
Copy link
Member

A simple instance of UIScrollView with UITextField in contentView. I can attach a sample project if it's needed.

RxKeyboard.instance.visibleHeight
   .debug("RxKeyboard")
   .drive(onNext: { [scrollView] in scrollView?.contentInset.bottom = $0 })
   .disposed(by: disposeBag)

scrollView.rx.observe(UIEdgeInsets.self, "contentInset")
  .debug("ScrollView")
  .subscribe()
  .disposed(by: disposeBag)

After assigning zero (keyboard hides) it reverts back to previous value. Output:

2019-07-16 13:16:14.546: RxKeyboard -> Event next(0.0)
2019-07-16 13:16:14.547: ScrollView -> Event next(Optional(__C.UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0)))
2019-07-16 13:16:14.548: ScrollView -> Event next(Optional(__C.UIEdgeInsets(top: 0.0, left: 0.0, bottom: 315.0, right: 0.0)))

Maybe, it's not RxKeyboard problem, however implementing it with raw NotificationCenter resolves the issue.
Changing RxKeyboardsubscription code to async (code smell) also resolves the issue:

RxKeyboard.instance.visibleHeight
    .asObservable()
    .observeOn(MainScheduler.asyncInstance)
    .bind { [scrollView] in scrollView?.contentInset.bottom = $0 }
    .disposed(by: disposeBag)

Maybe I just don't understand something. Could u please share your thoughts?

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

No branches or pull requests

1 participant