Jobeso / react-native-whatsapp-stickers

Integrate sticker packs for WhatsApp with your react-native app
Other
81 stars 30 forks source link

TypeError: _reactNativeWhatsappStickers.default.send is not a function (it is undefined) #93

Open darkdeathoriginal opened 4 months ago

darkdeathoriginal commented 4 months ago

ERROR TypeError: _reactNativeWhatsappStickers.default.send is not a function (it is undefined), js engine: hermes

import React, { useEffect, useState } from 'react'
import { Alert, Button, Platform, Text, View } from 'react-native'
import RNWhatsAppStickers from 'react-native-whatsapp-stickers'

const config = {
  identifier: 'assets',
  name: 'MyProject Stickers',
  publisher: 'John Doe',
  publisherEmail: 'xyz@myproject.xy',
  publisherWebsite: 'https://github.com/Jobeso/react-native-whatsapp-stickers',
  privacyPolicyWebsite:
    'https://github.com/Jobeso/react-native-whatsapp-stickers',
  licenseAgreementWebsite:
    'https://github.com/Jobeso/react-native-whatsapp-stickers/blob/master/LICENSE',
  stickers: [
    {
      fileName: 'temp.webp',
      emojis: ['☕', '🙂'],
    },
  ],
}

const { stickers, ...packConfig } = config

const logError = e => {
  console.log(e)
  Alert.alert('Error', e.message)
}

const sendStickerPack = () => {
  if (Platform.OS === 'ios') {
    RNWhatsAppStickers.createStickerPack(packConfig)
      .then(() => {
        const promises = stickers.map(item =>
          RNWhatsAppStickers.addSticker(item.fileName, item.emojis)
        )
        Promise.all(promises).then(() => RNWhatsAppStickers.send())
      })
      .catch(logError)
  } else {
    RNWhatsAppStickers.send('myprojectstickers', 'MyProject Stickers')
      .then(() => console.log('success'))
      .catch(logError)
  }
}

const TextBold = ({ children }) => (
  <Text style={{ fontWeight: 'bold', fontSize: 16 }}>{children}</Text>
)

export default function App() {
  const [isAvailable, setIsAvailable] = useState(false)

  useEffect(() => {
    RNWhatsAppStickers.isWhatsAppAvailable()
      .then(setIsAvailable)
      .catch(logError)
  }, [])

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text style={{ fontSize: 28, fontWeight: 'bold', marginBottom: 48 }}>
        RNWhatsAppStickers
      </Text>
      <Text style={{ marginBottom: 24, fontSize: 16 }}>
        WhatsApp is{' '}
        {isAvailable ? (
          <TextBold>available</TextBold>
        ) : (
          <TextBold>not available</TextBold>
        )}
      </Text>
      {isAvailable && (
        <Button title="Send Stickers" onPress={sendStickerPack} />
      )}
    </View>
  )
}