Skip to content

Commit ac4d90f

Browse files
authored
Merge pull request #77 from forem/release-1.0.17
Release 1.0.17 + Show hide bottom bar on vertical scroll
2 parents e5d1562 + d267045 commit ac4d90f

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

app/src/main/java/com/foremlibrary/app/MainActivity.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.widget.FrameLayout
88
import android.widget.ImageView
99
import android.widget.TextView
1010
import androidx.appcompat.app.AppCompatActivity
11+
import androidx.constraintlayout.widget.ConstraintLayout
1112
import com.forem.webview.WebViewConstants
1213
import com.forem.webview.WebViewFragment
1314
import com.forem.webview.utils.WebViewStatus
@@ -34,6 +35,7 @@ class MainActivity : AppCompatActivity() {
3435

3536
private var currentForem = DEV_TO
3637

38+
private lateinit var bottomNavigationBar: ConstraintLayout
3739
private lateinit var loadingViewContainer: FrameLayout
3840
private lateinit var foremNameTextView: TextView
3941
private lateinit var backImageView: ImageView
@@ -51,6 +53,7 @@ class MainActivity : AppCompatActivity() {
5153
loadOrUpdateFragment(url)
5254
}
5355

56+
bottomNavigationBar = findViewById(R.id.bottom_navigation_container)
5457
loadingViewContainer = findViewById(R.id.loading_view_container)
5558
foremNameTextView = findViewById(R.id.forem_name_text_view)
5659
backImageView = findViewById(R.id.back_image_view)
@@ -128,6 +131,13 @@ class MainActivity : AppCompatActivity() {
128131
loadingViewContainer.visibility = View.GONE
129132
}
130133
}
134+
webViewFragment.hideBottomNavigationBar.observe(this) { hideBottomBar ->
135+
if (hideBottomBar) {
136+
bottomNavigationBar.visibility = View.GONE
137+
} else {
138+
bottomNavigationBar.visibility = View.VISIBLE
139+
}
140+
}
131141
} else {
132142
getWebViewFragment()?.updateForemInstance(url)
133143
}

foremwebview/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ plugins {
44
id 'maven-publish'
55
}
66
ext{
7-
version_code = 16
8-
version_name = "1.0.16"
7+
version_code = 17
8+
version_name = "1.0.17"
99
}
1010

1111
android {

foremwebview/src/main/java/com/forem/webview/WebViewFragment.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)