@@ -77,6 +77,11 @@ class WebViewFragment : Fragment(), FileChooserListener {
7777 /* * Provides an observable which can reflect the current status of WebView. */
7878 val currentWebViewStatus = MutableLiveData (WebViewStatus .LOADING )
7979
80+ // This is required so as to compare with next upcoming y coordinate and accordingly decide
81+ // if the scroll/movement was upward or downward.
82+ private var currentYCoordinate = 0
83+ val hideBottomNavigationBar = MutableLiveData (false )
84+
8085 private val imagePickerLauncher =
8186 registerForActivityResult(ActivityResultContracts .StartActivityForResult ()) { result ->
8287 if (result.resultCode == Activity .RESULT_OK && result.data != null && result.data?.data != null ) {
@@ -97,6 +102,7 @@ class WebViewFragment : Fragment(), FileChooserListener {
97102 val view = inflater.inflate(R .layout.web_view_fragment, container, false )
98103
99104 currentWebViewStatus.value = WebViewStatus .LOADING
105+ hideBottomNavigationBar.value = false
100106
101107 noInternetConnectionContainer = view.findViewById(R .id.no_internet_connection_container)
102108 webView = view.findViewById(R .id.web_view)
@@ -187,6 +193,25 @@ class WebViewFragment : Fragment(), FileChooserListener {
187193 webView!! .webChromeClient = ForemWebChromeClient (fileChooserListener = this )
188194
189195 webView!! .loadUrl(baseUrl)
196+ setWebViewScrollListener(webView!! )
197+ }
198+
199+ private fun setWebViewScrollListener (webView : WebView ) {
200+ webView.viewTreeObserver.addOnScrollChangedListener {
201+ when {
202+ currentYCoordinate > webView.scrollY -> {
203+ hideBottomNavigationBar.value = false
204+ }
205+ currentYCoordinate <= webView.scrollY -> {
206+ hideBottomNavigationBar.value = true
207+ }
208+ else -> {
209+ // Save side check, will never arise ideally
210+ hideBottomNavigationBar.value = false
211+ }
212+ }
213+ currentYCoordinate = webView.scrollY
214+ }
190215 }
191216
192217 @SuppressLint(" SetJavaScriptEnabled" )
@@ -316,7 +341,7 @@ class WebViewFragment : Fragment(), FileChooserListener {
316341 } else {
317342 destroyOauthWebView()
318343 }
319- } else if (oauthWebView == null && webView!= null && webView!! .canGoBack()) {
344+ } else if (oauthWebView == null && webView != null && webView!! .canGoBack()) {
320345 // Case where oauthWebView is fully inactive.
321346 webView?.goBack()
322347 } else {
0 commit comments