-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reactions): emoji picker (#2311)
Co-authored-by: Yamil Medina <[email protected]>
- Loading branch information
1 parent
b766887
commit b813a5f
Showing
8 changed files
with
495 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/src/main/kotlin/com/wire/android/ui/emoji/DraggableByHandleBottomSheetBehavior.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.ui.emoji | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.MotionEvent | ||
import android.view.View | ||
import androidx.coordinatorlayout.widget.CoordinatorLayout | ||
import com.google.android.material.bottomsheet.BottomSheetBehavior | ||
|
||
class DraggableByHandleBottomSheetBehavior<V : View>( | ||
context: Context, | ||
attributeSet: AttributeSet | ||
) : BottomSheetBehavior<V>(context, attributeSet) { | ||
var dragHandle: View? = null | ||
|
||
override fun onInterceptTouchEvent(parent: CoordinatorLayout, child: V, event: MotionEvent): Boolean { | ||
dragHandle?.let { | ||
isDraggable = parent.isPointInChildBounds(it, event.x.toInt(), event.y.toInt()) | ||
} | ||
return super.onInterceptTouchEvent(parent, child, event) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
app/src/main/kotlin/com/wire/android/ui/emoji/EmojiPicker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.ui.emoji | ||
|
||
import android.widget.LinearLayout | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.emoji2.emojipicker.EmojiPickerView | ||
import com.google.android.material.bottomsheet.BottomSheetDragHandleView | ||
|
||
@Composable | ||
fun EmojiPickerBottomSheet( | ||
isVisible: Boolean, | ||
onDismiss: () -> Unit = {}, | ||
onEmojiSelected: (emoji: String) -> Unit | ||
) { | ||
val context = LocalContext.current | ||
val dialog = remember { | ||
HandleDraggableBottomSheetDialog(context).apply { | ||
setContentView( | ||
LinearLayout(context).apply { | ||
orientation = LinearLayout.VERTICAL | ||
val handle = BottomSheetDragHandleView(context) | ||
getBehavior().dragHandle = handle | ||
addView(handle) | ||
addView( | ||
EmojiPickerView(context).apply { | ||
setOnEmojiPickedListener { emojiViewItem -> | ||
onEmojiSelected(emojiViewItem.emoji) | ||
} | ||
} | ||
) | ||
} | ||
) | ||
setOnCancelListener { onDismiss.invoke() } | ||
} | ||
} | ||
if (isVisible) { | ||
dialog.show() | ||
} else { | ||
dialog.hide() | ||
} | ||
} |
Oops, something went wrong.