반응형
기본 방식 대응 - 공유 방법 취소 이벤트
나는 Android에서 콘텐츠를 공유하기 위해 Resact Native Share Method(https://facebook.github.io/react-native/docs/share.html))를 사용하고 있다.
설명서에 따라 다음과 같은 방법으로 사용할 수 있다.
Share.share({
message: 'React Native | A framework for building native apps using React'
})
.then((result) => {
console.log(result.action) // returns sharedAction
})
.catch((error) => {
console.log(error)
})
그래서 우리가 전화할 때Share
방법, 우리는 결과를 얻을 것이다.then
그리고 우리가 메시지 내용을 공유할 수 있는 앱 목록을 포함하는 팝업 창이 나타난다.
문제:
팝업 창에는 또한cancel
버튼, 즉 사용자가 클릭하면 윈도우가 닫히지만 문서를 캡처할 수 있는 방법이 없다.
사용자가 클릭할 때 일부 작업을 수행하려고 하는데 취소 이벤트를 캡처할 수 있는 방법이 없을까?
조언해줘서 고마워 :)
share discledAction에는 옵션이 있지만 불행히도 이 옵션은 IOS에만 해당된다.prople "FailOnCancel"을 true와 함께 react-native-native-share를 사용할 수 있으며, 안드로이드와 ios 모두에서 작동한다.
샘플 코드
import React, { Component } from "react";
import { Button } from "react-native";
import Share from "react-native-share";
export default class ShareExample extends Component {
onShare = async () => {
const shareOptions = {
title: "Share file",
social: Share.Social.EMAIL,
failOnCancel: true
};
try {
const ShareResponse = await Share.open(shareOptions);
//setResult(JSON.stringify(ShareResponse, null, 2));
} catch (error) {
console.log("Error =>", error);
}
};
render() {
return <Button onPress={this.onShare} title="Share" />;
}
}
앱 미리보기
이것이 도움이 될 것이다.
import React, {Component} from 'react';
import {Share, Button} from 'react-native';
class ShareExample extends Component {
onShare = async () => {
try {
const result = await Share.share({
message:
'React Native | A framework for building native apps using React',
});
if (result.action === Share.sharedAction) {
if (result.activityType) {
// shared with activity type of result.activityType
} else {
// shared
}
} else if (result.action === Share.dismissedAction) {
// dismissed
}
} catch (error) {
alert(error.message);
}
};
render() {
return <Button onPress={this.onShare} title="Share" />;
}
}
참조URL: https://stackoverflow.com/questions/44095828/react-native-share-method-cancel-event
반응형
'IT이야기' 카테고리의 다른 글
파이톤 대본에 #!(쉐뱅)을 넣어야 하나, 어떤 형식을 취해야 하나? (0) | 2022.03.24 |
---|---|
Vuejs : 오류:현재 위치로 중복 탐색 방지: (0) | 2022.03.24 |
Vue.js에서 생성된 이벤트와 마운트된 이벤트 간의 차이 (0) | 2022.03.24 |
각도2에서 'jquery' 이름을 찾을 수 없음 (0) | 2022.03.23 |
python에서 받아쓰기의 깊은 사본 (0) | 2022.03.23 |