From 39ccba98acb1403584053aa4aa98bbc07f0fa87d Mon Sep 17 00:00:00 2001 From: gulerbu Date: Tue, 27 Jul 2021 13:46:35 +0300 Subject: [PATCH 1/3] Fix webview focus problem --- buildSrc/src/main/kotlin/ComponentVersions.kt | 2 +- .../uicomponents/dialogs/DialogFragment.kt | 30 +++++++++++++++++-- .../src/main/res/layout/fragment_dialog.xml | 7 ++--- sample/src/main/AndroidManifest.xml | 4 ++- .../trendyol/uicomponents/DialogsActivity.kt | 4 ++- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/buildSrc/src/main/kotlin/ComponentVersions.kt b/buildSrc/src/main/kotlin/ComponentVersions.kt index 8e103609..fa8f2a03 100644 --- a/buildSrc/src/main/kotlin/ComponentVersions.kt +++ b/buildSrc/src/main/kotlin/ComponentVersions.kt @@ -5,7 +5,7 @@ object ComponentVersions { const val ratingBarVersion = "1.0.2" const val imageSliderVersion = "1.0.8" const val phoneNumberVersion = "1.0.2" - const val dialogsVersion = "1.2.4" + const val dialogsVersion = "1.2.5" const val cardInputViewVersion = "1.1.2" const val quantityPickerViewVersion = "1.2.4" const val timelineViewVersion = "1.0.0" diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt index e954473c..8eabe7df 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt @@ -6,11 +6,14 @@ import android.text.SpannableString import android.text.method.LinkMovementMethod import android.text.util.Linkify import android.view.LayoutInflater +import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.view.ViewGroup.FOCUS_AFTER_DESCENDANTS +import android.view.ViewGroup.FOCUS_DOWN import android.view.ViewOutlineProvider import android.webkit.WebChromeClient +import android.webkit.WebViewClient import androidx.core.widget.doAfterTextChanged import androidx.fragment.app.FragmentManager import androidx.lifecycle.ViewModelProviders @@ -27,6 +30,7 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { var rightButtonClickListener: ((DialogFragment) -> Unit)? = null var onItemSelectedListener: ((DialogFragment, Int) -> Unit)? = null var onItemReselectedListener: ((DialogFragment, Int) -> Unit)? = null + private var lastScrollPosY : Int = 0 internal lateinit var binding: FragmentDialogBinding private val dialogArguments by lazy(LazyThreadSafetyMode.NONE) { @@ -92,11 +96,31 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { dialogListViewModel.clearSearch() } - constraintLayout.descendantFocusability = FOCUS_AFTER_DESCENDANTS - setUpViewModel(items) } } + + /* public void setListenerToRootView() { + final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content); + activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + + int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight(); + if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard. + Toast.makeText(getApplicationContext(), "Gotcha!!! softKeyboardup", 0).show(); + + if (isOpened == false) { + //Do two things, make the view top visible and the editText smaller + } + isOpened = true; + } else if (isOpened == true) { + Toast.makeText(getApplicationContext(), "softkeyborad Down!!!", 0).show(); + isOpened = false; + } + } + }); + } */ } private fun initializeRecyclerView() = with(binding.recyclerViewItems) { @@ -153,9 +177,11 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { visibility = viewState.getWebViewContentVisibility() if (visibility == View.VISIBLE) { webChromeClient = WebChromeClient() + webViewClient = WebViewClient() dialogArguments.webViewBuilder?.invoke(webViewContent) loadWebViewContent(viewState.webViewContent) + setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY -> lastScrollPosY = scrollY } } } with(editTextSearch) { diff --git a/libraries/dialogs/src/main/res/layout/fragment_dialog.xml b/libraries/dialogs/src/main/res/layout/fragment_dialog.xml index 223d14d4..0d3fdc22 100644 --- a/libraries/dialogs/src/main/res/layout/fragment_dialog.xml +++ b/libraries/dialogs/src/main/res/layout/fragment_dialog.xml @@ -10,14 +10,12 @@ @@ -49,8 +47,7 @@ + android:layout_height="match_parent"> - + + diff --git a/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt b/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt index 08bd20c2..85e9b708 100644 --- a/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt +++ b/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt @@ -3,6 +3,7 @@ package com.trendyol.uicomponents import android.os.Bundle import android.text.SpannableString import android.text.SpannableStringBuilder +import android.webkit.WebViewClient import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AppCompatActivity @@ -121,10 +122,11 @@ class DialogsActivity : AppCompatActivity() { title = "Info Dialog Sample" showCloseButton = true closeButtonListener = infoDialogClosed - webViewContent = WebViewContent.UrlContent("https://kargotakip.trendyol.com/") + webViewContent = WebViewContent.UrlContent("https://kargotakip.trendyol.com/?token=ed396950-c70f-48b8-8902-931f19b440d4") webViewBuilder = { settings.javaScriptEnabled = true settings.domStorageEnabled = true + webViewClient = WebViewClient() } }.showDialog(supportFragmentManager) From 0438b80adfb1f9e7193e576c5e74bec128f7f377 Mon Sep 17 00:00:00 2001 From: gulerbu Date: Tue, 27 Jul 2021 14:01:32 +0300 Subject: [PATCH 2/3] Update web address --- .../src/main/java/com/trendyol/uicomponents/DialogsActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt b/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt index 85e9b708..68edf9a9 100644 --- a/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt +++ b/sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt @@ -122,7 +122,7 @@ class DialogsActivity : AppCompatActivity() { title = "Info Dialog Sample" showCloseButton = true closeButtonListener = infoDialogClosed - webViewContent = WebViewContent.UrlContent("https://kargotakip.trendyol.com/?token=ed396950-c70f-48b8-8902-931f19b440d4") + webViewContent = WebViewContent.UrlContent("https://github.com/Trendyol/android-ui-components") webViewBuilder = { settings.javaScriptEnabled = true settings.domStorageEnabled = true From c72ff39e7a77896c41ea8e7ebb2dd0da922c0ef6 Mon Sep 17 00:00:00 2001 From: gulerbu Date: Tue, 27 Jul 2021 14:09:40 +0300 Subject: [PATCH 3/3] Remove commented out lines --- .../uicomponents/dialogs/DialogFragment.kt | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt index 8eabe7df..bc549092 100644 --- a/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt +++ b/libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/DialogFragment.kt @@ -30,7 +30,6 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { var rightButtonClickListener: ((DialogFragment) -> Unit)? = null var onItemSelectedListener: ((DialogFragment, Int) -> Unit)? = null var onItemReselectedListener: ((DialogFragment, Int) -> Unit)? = null - private var lastScrollPosY : Int = 0 internal lateinit var binding: FragmentDialogBinding private val dialogArguments by lazy(LazyThreadSafetyMode.NONE) { @@ -99,28 +98,6 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { setUpViewModel(items) } } - - /* public void setListenerToRootView() { - final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content); - activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - - int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight(); - if (heightDiff > 100) { // 99% of the time the height diff will be due to a keyboard. - Toast.makeText(getApplicationContext(), "Gotcha!!! softKeyboardup", 0).show(); - - if (isOpened == false) { - //Do two things, make the view top visible and the editText smaller - } - isOpened = true; - } else if (isOpened == true) { - Toast.makeText(getApplicationContext(), "softkeyborad Down!!!", 0).show(); - isOpened = false; - } - } - }); - } */ } private fun initializeRecyclerView() = with(binding.recyclerViewItems) { @@ -181,7 +158,6 @@ class DialogFragment internal constructor() : BaseBottomSheetDialog() { dialogArguments.webViewBuilder?.invoke(webViewContent) loadWebViewContent(viewState.webViewContent) - setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY -> lastScrollPosY = scrollY } } } with(editTextSearch) {