Skip to content

Commit

Permalink
Fix webview focus problem
Browse files Browse the repository at this point in the history
  • Loading branch information
gulerbu authored and gulerbu committed Jul 27, 2021
1 parent c9ba131 commit 39ccba9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/ComponentVersions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions libraries/dialogs/src/main/res/layout/fragment_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical">

<LinearLayout
android:id="@+id/viewTitleBackground"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:focusableInTouchMode="true"
android:paddingStart="@dimen/dialogs_margin_outer"
android:paddingEnd="@dimen/dialogs_margin_outer">

Expand Down Expand Up @@ -49,8 +47,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">
android:layout_height="match_parent">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/imageContent"
Expand Down Expand Up @@ -82,6 +79,8 @@
android:layout_height="wrap_content"
android:paddingTop="@dimen/dialogs_margin_inner"
android:paddingBottom="@dimen/dialogs_margin_inner"
android:focusable="true"
android:focusableInTouchMode="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textContent"
Expand Down
4 changes: 3 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
</intent-filter>
</activity>
<activity android:name=".RatingBarActivity" />
<activity android:name=".DialogsActivity" />
<activity android:name=".DialogsActivity"
android:windowSoftInputMode="adjustResize">
</activity>
<activity android:name=".ImageSliderActivity" />
<activity android:name=".PhoneNumberActivity" />
<activity android:name=".ToolbarActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 39ccba9

Please sign in to comment.