Skip to content

Commit 387ed79

Browse files
patch/2.13.1
Patch/2.13.1
2 parents 4732d18 + 60cc1b2 commit 387ed79

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

kommunicate/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android {
1818
compileSdk 34
1919
targetSdkVersion 35
2020
versionCode 1
21-
versionName "2.13.0"
21+
versionName "2.13.1"
2222
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2323
buildConfigField "String", "KOMMUNICATE_VERSION", "\"" + versionName + "\""
2424
buildConfigField "String", "CHAT_SERVER_URL", '"https://chat.kommunicate.io"'

kommunicateui/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ android {
1616
targetSdkVersion 35
1717
minSdkVersion 21
1818
versionCode 1
19-
versionName "2.13.0"
19+
versionName "2.13.1"
2020
buildToolsVersion = '34.0.0'
2121
consumerProguardFiles 'proguard-rules.txt'
2222
vectorDrawables.useSupportLibrary = true

kommunicateui/src/main/java/com/applozic/mobicomkit/uiwidgets/conversation/fragment/MobiComConversationFragment.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,11 +1196,21 @@ private void setupInsets() {
11961196
-1,
11971197
false
11981198
);
1199-
InsetHelper.configureSystemInsets(
1199+
InsetHelper.configureSystemInsetsWithKeyboard(
12001200
kmMessageLinearLayout,
12011201
0,
12021202
-1,
1203-
true
1203+
true,
1204+
(isVisible, keyboardHeight) -> {
1205+
if(isVisible
1206+
&& recyclerView != null
1207+
&& recyclerView.getAdapter() != null
1208+
&& recyclerView.getAdapter().getItemCount() > 0
1209+
) {
1210+
recyclerView.smoothScrollToPosition(recyclerView.getAdapter().getItemCount() - 1);
1211+
}
1212+
return null;
1213+
}
12041214
);
12051215
}
12061216

kommunicateui/src/main/java/com/applozic/mobicomkit/uiwidgets/utils/InsetHelper.kt

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package com.applozic.mobicomkit.uiwidgets.utils
22

3+
import android.animation.ValueAnimator
34
import android.view.View
45
import android.view.ViewGroup
6+
import android.view.animation.DecelerateInterpolator
7+
import androidx.core.animation.doOnEnd
58
import androidx.core.view.ViewCompat
69
import androidx.core.view.WindowInsetsCompat
710
import androidx.core.view.updateLayoutParams
811
import androidx.core.view.updatePadding
912

1013
/**
11-
* A utility object that helps manage system insets (like status bar, navigation bar, etc.)
14+
* A utility object that helps manage system insets (like status bar, navigation bar, keyboard, etc.)
1215
* by configuring padding or margin adjustments based on the system window insets.
16+
* Includes support for keyboard animations and edge-to-edge display.
1317
*/
1418
object InsetHelper {
1519

@@ -31,6 +35,12 @@ object InsetHelper {
3135
@JvmField
3236
val navigationTypeMask = WindowInsetsCompat.Type.navigationBars()
3337

38+
/**
39+
* [imeTypeMask] is a type mask for the software keyboard.
40+
*/
41+
@JvmField
42+
val imeTypeMask = WindowInsetsCompat.Type.ime()
43+
3444
/**
3545
* Configures the system insets with status bar to update either
3646
* padding or margin of the target view.
@@ -53,7 +63,18 @@ object InsetHelper {
5363
bottom: Int = -1,
5464
isPadding: Boolean = true
5565
) {
56-
configureInset(view, systemTypeMask, 0 , 0, top, bottom, isPadding)
66+
configureInset(view, systemTypeMask, 0, 0, top, bottom, isPadding)
67+
}
68+
69+
@JvmStatic
70+
fun configureSystemInsetsWithKeyboard(
71+
view: View,
72+
top: Int = -1,
73+
bottom: Int = -1,
74+
isPadding: Boolean = true,
75+
adjustForKeyboard: (isVisible: Boolean, keyboardHeight: Int) -> Unit
76+
) {
77+
configureInset(view, systemTypeMask, 0, 0, top, bottom, isPadding, adjustForKeyboard)
5778
}
5879

5980
/**
@@ -73,6 +94,7 @@ object InsetHelper {
7394
* @param top The padding or margin to apply on the top side. Default is -1 (which means apply the inset value).
7495
* @param bottom The padding or margin to apply on the bottom side. Default is -1 (which means apply the inset value).
7596
* @param isPadding If true, the function adjusts the padding of the view. If false, it adjusts the margins of the view. Default is true.
97+
* @param adjustForKeyboard the function will adjust the view when the keyboard appears/disappears.
7698
*/
7799
@JvmStatic
78100
fun configureInset(
@@ -82,23 +104,43 @@ object InsetHelper {
82104
right: Int = -1,
83105
top: Int = -1,
84106
bottom: Int = -1,
85-
isPadding: Boolean = true
107+
isPadding: Boolean = true,
108+
adjustForKeyboard: ((isVisible: Boolean, keyboardHeight: Int) -> Unit)? = null
86109
) {
110+
var lastKeyboardHeight = 0
111+
var wasKeyboardVisible = false
112+
87113
ViewCompat.setOnApplyWindowInsetsListener(view) { targetView, windowInsets ->
88114
val insets = windowInsets.getInsets(typeMask)
115+
val imeInsets = windowInsets.getInsets(imeTypeMask)
116+
val isKeyboardVisible = windowInsets.isVisible(WindowInsetsCompat.Type.ime())
117+
118+
// Combine insets if adjusting for keyboard
119+
val bottomInset = if (adjustForKeyboard != null && imeInsets.bottom > 0) {
120+
imeInsets.bottom
121+
} else {
122+
insets.bottom
123+
}
124+
125+
if (isKeyboardVisible != wasKeyboardVisible) {
126+
adjustForKeyboard?.invoke(isKeyboardVisible, lastKeyboardHeight)
127+
wasKeyboardVisible = isKeyboardVisible
128+
lastKeyboardHeight = resolveInset(bottom, bottomInset)
129+
}
130+
89131
if (isPadding) {
90132
targetView.updatePadding(
91133
left = resolveInset(left, insets.left),
92134
right = resolveInset(right, insets.right),
93135
top = resolveInset(top, insets.top),
94-
bottom = resolveInset(bottom, insets.bottom)
136+
bottom = resolveInset(bottom, bottomInset)
95137
)
96138
} else {
97139
targetView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
98140
leftMargin = resolveInset(left, insets.left)
99141
rightMargin = resolveInset(right, insets.right)
100-
bottomMargin = resolveInset(bottom, insets.bottom)
101142
topMargin = resolveInset(top, insets.top)
143+
bottomMargin = resolveInset(bottom, bottomInset)
102144
}
103145
}
104146
// Return CONSUMED to prevent further insets handling by the system

0 commit comments

Comments
 (0)