Пожалуйста, прикрепите метод к компоненту по реализации share - PullRequest
0 голосов
/ 11 февраля 2020

Я использую реактивный общий ресурс вact-native, однако при реализации кода появляется сообщение об ошибке:

. Пожалуйста, присоедините метод к компоненту

Ниже приведена моя функция общего доступа:

shareProduct =async (data) => {
     console.log(data)
      const shareOptions = {
        title: 'Share file',
        failOnCancel: false,
        urls: [this.state.data.urlImg],
        message: this.state.data.title,
        message: this.state.data.description
      };     
      try {
        const ShareResponse = await Share.open(shareOptions);
        setResult(JSON.stringify(ShareResponse, null, 2));
      } catch (error) {
        console.log('Error =>', error);
        setResult('error: '.concat(getErrorString(error)));
      }
    };

Я вызвал вышеуказанную функцию следующим образом:

<TouchableOpacity onPress={
          ()=>
         this.shareProduct
        }>
        <Button
          icon={<Icon name="share" size={20} color="pink" />}
          type="outline"
        />
        </TouchableOpacity>

Мои журналы:

 {"product": {"__v": 0, "_id": "5e301696f75182463c6874ed", "color": "Space Grey", "colors": [], "description": "6.5-inch Super Retina XDR OLED display
Water and dust resistant (4 meters for up to 30 minutes, IP68)
Triple-camera system with 12MP Ultra Wide, Wide, and Telephoto cameras; Night mode, Portrait mode, and 4K video up to 60fps
12MP TrueDepth front camera with Portrait Mode, 4K video, and Slo-Mo
Face ID for secure authentication and Apple Pay
A13 Bionic chip with third-generation Neural Engine
Fast charge with 18W adapter included
Wireless charging
Manufacturer Detail: Apple Inc, One Apple Park Way, Cupertino, CA 95014, USA", "downloads": 70, "nameImg": "61jgfLBydjL._SL1024_-1580209807807.jpg", "nameVid": "videoplayback (1)-1580209807809.mp4", "price": 99900, "sellerID": "13755902031", "sellerName": "Appario", "size": "5.8-inch", "sizes": [], "title": "Apple iPhone 11 Pro", "typeImg": "image/jpeg", "typeVid": "video/mp4", "uploadedOn": "2020-01-28T11:10:14.244Z", "urlImg": "https://atiiproductmediafiles.s3.ap-south-1.amazonaws.com/61jgfLBydjL._SL1024_-1580209807807.jpg", "urlVid": "https://atiiproductmediafiles.s3.ap-south-1.amazonaws.com/videoplayback+%281%29-1580209807809.mp4"}, "user": {"__v": 12, "_id": "5e413c58a520db6386a9417b", "address": [], "bankDetails": [], "changes": [], "checkout": [], "like": ["5e301696f75182463c6874ed", "5e301696f75182463c6874ed", "5e301696f75182463c6874ed", "5e301696f75182463c6874ed", "5e301696f75182463c6874ed", "5e301696f75182463c6874ed", "5e301696f75182463c6874ed", "5e301696f75182463c6874ed", "5e301696f75182463c6874ed", "5e301696f75182463c6874ed", "5e301696f75182463c6874ed"], "links": [], "mobile": 8697779335, "orderPlaced": [], "orders": [], "registeredOn": "2020-02-10T11:19:52.234Z", "userDetails": ["5e413c58a520db6386a9417c"], "wishlist": []}}
 LOG  Please attach a method to this component

Ответы [ 2 ]

0 голосов
/ 12 февраля 2020

функция onPress должна была вызываться внутри кнопки Component, как

<Button
        onPress={

         this.shareProduct 
        }
          icon={<Icon name="share" size={20} color="pink" />}
          type="outline"
        />

И она сортируется!

Странно, но она работала !!

0 голосов
/ 11 февраля 2020

вы вызвали неправильный метод в функции onPress с именем "whatsappProduct"

вы должны вызвать "shareProduct" следующим образом

<TouchableOpacity onPress={this.shareProduct}>
    <Button
      icon={<Icon name="share" size={20} color="pink" />}
      type="outline"
    />
 </TouchableOpacity>
...