vendor expo-ized emoji popup
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Alan Hughes
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,3 @@
|
||||
# expo-emoji-picker
|
||||
|
||||
Based on [react-native-emoji-popup](https://github.com/okwasniewski/react-native-emoji-popup) and [expo-emoji-picker](https://github.com/alanjhughes/expo-emoji-picker)
|
||||
@@ -0,0 +1,46 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
group = 'expo.community.modules.emojipicker'
|
||||
version = '0.1.0'
|
||||
|
||||
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
||||
apply from: expoModulesCorePlugin
|
||||
applyKotlinExpoModulesCorePlugin()
|
||||
useCoreDependencies()
|
||||
useExpoPublishing()
|
||||
|
||||
// If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
|
||||
// The Android SDK versions will be bumped from time to time in SDK releases and may introduce breaking changes in your module code.
|
||||
// Most of the time, you may like to manage the Android SDK versions yourself.
|
||||
def useManagedAndroidSdkVersions = false
|
||||
if (useManagedAndroidSdkVersions) {
|
||||
useDefaultAndroidSdkVersions()
|
||||
} else {
|
||||
buildscript {
|
||||
// Simple helper that allows the root project to override versions declared by this library.
|
||||
ext.safeExtGet = { prop, fallback ->
|
||||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
||||
}
|
||||
}
|
||||
project.android {
|
||||
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
||||
defaultConfig {
|
||||
minSdkVersion safeExtGet("minSdkVersion", 21)
|
||||
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "expo.community.modules.emojipicker"
|
||||
defaultConfig {
|
||||
versionCode 1
|
||||
versionName "0.1.0"
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
dependencies {
|
||||
implementation "androidx.emoji2:emoji2-emojipicker:1.5.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<manifest>
|
||||
</manifest>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package expo.community.modules.emojipicker
|
||||
|
||||
import expo.modules.kotlin.modules.Module
|
||||
import expo.modules.kotlin.modules.ModuleDefinition
|
||||
import java.net.URL
|
||||
|
||||
class EmojiPickerModule : Module() {
|
||||
override fun definition() = ModuleDefinition {
|
||||
Name("EmojiPicker")
|
||||
|
||||
View(EmojiPickerModuleView::class) {
|
||||
Events("onEmojiSelected")
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package expo.community.modules.emojipicker
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import androidx.emoji2.emojipicker.EmojiPickerView
|
||||
import expo.modules.kotlin.AppContext
|
||||
import expo.modules.kotlin.viewevent.EventDispatcher
|
||||
import expo.modules.kotlin.views.ExpoView
|
||||
|
||||
|
||||
@SuppressLint("ViewConstructor")
|
||||
class EmojiPickerModuleView(context: Context, appContext: AppContext) :
|
||||
ExpoView(context, appContext) {
|
||||
private var emojiView: EmojiPickerView = EmojiPickerView(context)
|
||||
private val onEmojiSelected by EventDispatcher()
|
||||
|
||||
init {
|
||||
setupView()
|
||||
}
|
||||
|
||||
private fun setupView() {
|
||||
addView(
|
||||
emojiView, LayoutParams(
|
||||
LayoutParams.MATCH_PARENT,
|
||||
LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
|
||||
emojiView.setOnEmojiPickedListener { emoji ->
|
||||
onEmojiSelected(mapOf("emoji" to emoji.emoji))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration?) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
removeView(emojiView)
|
||||
setupView()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"platforms": ["apple", "android"],
|
||||
"apple": {
|
||||
"modules": ["EmojiPickerModule"]
|
||||
},
|
||||
"android": {
|
||||
"modules": ["expo.community.modules.emojipicker.EmojiPickerModule"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export {default as EmojiPicker} from './src/EmojiPicker'
|
||||
export {default} from './src/EmojiPickerModule'
|
||||
export * from './src/EmojiPickerModule.types'
|
||||
@@ -0,0 +1,30 @@
|
||||
require 'json'
|
||||
|
||||
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'EmojiPickerModule'
|
||||
s.version = package['version']
|
||||
s.summary = package['description']
|
||||
s.description = package['description']
|
||||
s.license = package['license']
|
||||
s.author = package['author']
|
||||
s.homepage = package['homepage']
|
||||
s.platforms = {
|
||||
:ios => '15.1',
|
||||
:tvos => '15.1'
|
||||
}
|
||||
s.swift_version = '5.4'
|
||||
s.source = { git: 'https://github.com/alanjhughes/expo-emoji-picker' }
|
||||
s.static_framework = true
|
||||
|
||||
s.dependency 'ExpoModulesCore'
|
||||
s.dependency 'MCEmojiPicker'
|
||||
|
||||
# Swift/Objective-C compatibility
|
||||
s.pod_target_xcconfig = {
|
||||
'DEFINES_MODULE' => 'YES',
|
||||
}
|
||||
|
||||
s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
import ExpoModulesCore
|
||||
|
||||
public class EmojiPickerModule: Module {
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("EmojiPicker")
|
||||
|
||||
View(EmojiPickerView.self) {
|
||||
Events("onEmojiSelected")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import ExpoModulesCore
|
||||
import WebKit
|
||||
import MCEmojiPicker
|
||||
|
||||
class EmojiPickerView: ExpoView, MCEmojiPickerDelegate {
|
||||
let onEmojiSelected = EventDispatcher()
|
||||
|
||||
override func layoutSubviews() {
|
||||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
|
||||
self.addGestureRecognizer(tapGesture)
|
||||
}
|
||||
|
||||
@objc func handleTap(_ gesture: UITapGestureRecognizer) {
|
||||
presentEmojiPicker()
|
||||
}
|
||||
|
||||
func presentEmojiPicker() {
|
||||
let emojiPicker = MCEmojiPickerViewController()
|
||||
let reactRootVC = reactViewController()
|
||||
emojiPicker.sourceView = self
|
||||
emojiPicker.delegate = self
|
||||
reactRootVC?.present(emojiPicker, animated: true)
|
||||
}
|
||||
|
||||
func didGetEmoji(emoji: String) {
|
||||
onEmojiSelected([
|
||||
"emoji": emoji
|
||||
])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import {type EmojiPickerViewProps} from './EmojiPickerModule.types'
|
||||
import EmojiPickerNativeView from './EmojiPickerView'
|
||||
|
||||
const EmojiPicker = ({onEmojiSelected}: EmojiPickerViewProps) => {
|
||||
return (
|
||||
<EmojiPickerNativeView
|
||||
onEmojiSelected={emoji => {
|
||||
onEmojiSelected(emoji)
|
||||
}}
|
||||
style={styles}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = {
|
||||
flex: 1,
|
||||
width: '100%',
|
||||
backgroundColor: 'white',
|
||||
} as const
|
||||
|
||||
export default EmojiPicker
|
||||
@@ -0,0 +1,15 @@
|
||||
import {type EmojiPickerViewProps} from './EmojiPickerModule.types'
|
||||
import EmojiPickerNativeView from './EmojiPickerView'
|
||||
|
||||
const EmojiPicker = ({children, onEmojiSelected}: EmojiPickerViewProps) => {
|
||||
return (
|
||||
<EmojiPickerNativeView
|
||||
onEmojiSelected={emoji => {
|
||||
onEmojiSelected(emoji)
|
||||
}}>
|
||||
{children}
|
||||
</EmojiPickerNativeView>
|
||||
)
|
||||
}
|
||||
|
||||
export default EmojiPicker
|
||||
@@ -0,0 +1,5 @@
|
||||
import {NativeModule, requireNativeModule} from 'expo'
|
||||
|
||||
declare class EmojiPickerModule extends NativeModule {}
|
||||
|
||||
export default requireNativeModule<EmojiPickerModule>('EmojiPicker')
|
||||
@@ -0,0 +1,20 @@
|
||||
import {type ViewProps} from 'react-native'
|
||||
|
||||
export type EmojiSelectionListener = (event: {
|
||||
nativeEvent: SelectionEvent
|
||||
}) => void
|
||||
|
||||
export type SelectionEvent = {
|
||||
emoji: string
|
||||
}
|
||||
|
||||
export type EmojiPickerViewProps = ViewProps & {
|
||||
/*
|
||||
* Callback that will be called when an emoji is selected.
|
||||
*/
|
||||
onEmojiSelected: (emoji: string) => void
|
||||
}
|
||||
|
||||
export type EmojiPickerNativeViewProps = ViewProps & {
|
||||
onEmojiSelected: EmojiSelectionListener
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import {requireNativeView} from 'expo'
|
||||
import type * as React from 'react'
|
||||
|
||||
import {
|
||||
type EmojiPickerNativeViewProps,
|
||||
type EmojiPickerViewProps,
|
||||
} from './EmojiPickerModule.types'
|
||||
|
||||
const NativeView: React.ComponentType<EmojiPickerNativeViewProps> =
|
||||
requireNativeView('EmojiPicker')
|
||||
|
||||
export default function EmojiPicker(props: EmojiPickerViewProps) {
|
||||
return (
|
||||
<NativeView
|
||||
{...props}
|
||||
onEmojiSelected={({nativeEvent}) => {
|
||||
props.onEmojiSelected(nativeEvent.emoji)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -174,7 +174,6 @@
|
||||
"react-native-date-picker": "^5.0.12",
|
||||
"react-native-drawer-layout": "^4.1.6",
|
||||
"react-native-edge-to-edge": "^1.6.0",
|
||||
"react-native-emoji-popup": "^0.3.0",
|
||||
"react-native-gesture-handler": "2.25.0",
|
||||
"react-native-get-random-values": "~1.11.0",
|
||||
"react-native-image-crop-picker": "^0.42.0",
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import {useState} from 'react'
|
||||
import {Modal, Pressable, View} from 'react-native'
|
||||
// @ts-expect-error internal component, not supposed to be used directly
|
||||
// waiting on more customisability: https://github.com/okwasniewski/react-native-emoji-popup/issues/1#issuecomment-2737463753
|
||||
import EmojiPopupView from 'react-native-emoji-popup/src/EmojiPopupViewNativeComponent'
|
||||
import {SafeAreaView} from 'react-native-safe-area-context'
|
||||
import {msg, Trans} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import {Button, ButtonIcon} from '#/components/Button'
|
||||
import {TimesLarge_Stroke2_Corner0_Rounded} from '#/components/icons/Times'
|
||||
import {TimesLarge_Stroke2_Corner0_Rounded as CloseIcon} from '#/components/icons/Times'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {EmojiPicker} from '../../../modules/expo-emoji-picker'
|
||||
|
||||
export function EmojiPopup({
|
||||
children,
|
||||
@@ -34,13 +33,14 @@ export function EmojiPopup({
|
||||
|
||||
<Modal
|
||||
animationType="slide"
|
||||
transparent={true}
|
||||
visible={modalVisible}
|
||||
onRequestClose={() => setModalVisible(false)}>
|
||||
<View style={[a.flex_1, {backgroundColor: t.palette.white}]}>
|
||||
onRequestClose={() => setModalVisible(false)}
|
||||
transparent
|
||||
statusBarTranslucent
|
||||
navigationBarTranslucent>
|
||||
<SafeAreaView style={[a.flex_1, t.atoms.bg]}>
|
||||
<View
|
||||
style={[
|
||||
t.atoms.bg,
|
||||
a.pl_lg,
|
||||
a.pr_md,
|
||||
a.py_sm,
|
||||
@@ -61,21 +61,16 @@ export function EmojiPopup({
|
||||
variant="ghost"
|
||||
color="secondary"
|
||||
shape="round">
|
||||
<ButtonIcon icon={TimesLarge_Stroke2_Corner0_Rounded} />
|
||||
<ButtonIcon icon={CloseIcon} />
|
||||
</Button>
|
||||
</View>
|
||||
<EmojiPopupView
|
||||
onEmojiSelected={({
|
||||
nativeEvent: {emoji},
|
||||
}: {
|
||||
nativeEvent: {emoji: string}
|
||||
}) => {
|
||||
<EmojiPicker
|
||||
onEmojiSelected={emoji => {
|
||||
setModalVisible(false)
|
||||
onEmojiSelected(emoji)
|
||||
}}
|
||||
style={[a.flex_1, a.w_full]}
|
||||
/>
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
</Modal>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -1 +1 @@
|
||||
export {EmojiPopup} from 'react-native-emoji-popup'
|
||||
export {EmojiPicker as EmojiPopup} from '../../../modules/expo-emoji-picker'
|
||||
|
||||
@@ -16928,11 +16928,6 @@ react-native-edge-to-edge@1.6.0, react-native-edge-to-edge@^1.6.0:
|
||||
resolved "https://registry.yarnpkg.com/react-native-edge-to-edge/-/react-native-edge-to-edge-1.6.0.tgz#2ba63b941704a7f713e298185c26cde4d9e4b973"
|
||||
integrity sha512-2WCNdE3Qd6Fwg9+4BpbATUxCLcouF6YRY7K+J36KJ4l3y+tWN6XCqAC4DuoGblAAbb2sLkhEDp4FOlbOIot2Og==
|
||||
|
||||
react-native-emoji-popup@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/react-native-emoji-popup/-/react-native-emoji-popup-0.3.0.tgz#1d5635c29b25b47ac4e06fb60e12b04471f73b90"
|
||||
integrity sha512-6OvZYCd1Tq/MyiJQTA50CPxLBUOu7awpNpXZCIFZ7RAFCaJ/51O2aKKDj4xTrrNWp0LVr/95W97Poi7eYBGcLA==
|
||||
|
||||
react-native-gesture-handler@2.25.0:
|
||||
version "2.25.0"
|
||||
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-2.25.0.tgz#3a5a8912ea4f5e68ab211a9fa5a191c08ad50883"
|
||||
|
||||
Reference in New Issue
Block a user