일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- ChatGPT
- @types
- 게시판
- 마이너스의 의미
- .netcore
- TS70016
- JWT 토큰
- json pretty
- 웹퍼블리셔종말
- 터미널옵션
- pnpm
- 개발
- classNames
- typesinstall
- 아들에게
- 메일수신거부 프로세스
- 초보
- 스케쳐스아치핏
- JWT 토큰 인증 로그인 쿠키 설정
- 하마모양
- 곧아빠됨
- nodejs
- c#
- ts7016
- 개발언어
- asp.net core
- locofy.ai
- 웹퍼블리셔전망
- 메일수신거부처리
- 패키지관리자
- Today
- Total
I am maker
react type script function execute by name 본문
어떻게하는거야 ㅠㅠ
import React, {useRef, RefObject, MutableRefObject, useState} from 'react';
import {StatusBar, Text} from 'react-native';
import {WebView} from 'react-native-webview';
const sampleHtml = require('./sample/index.html');
const App = () => {
const webViewRef = useRef<WebView>(null);
const [text, setText] = useState<string>();
// /**
// * 화면에서 post를 던지면 react-native에서 받음
// */
// const handleMessage = (event: any) => {
// console.log('onWebViewMessage', JSON.parse(event.nativeEvent.data));
// let msgData;
// try {
// msgData = JSON.parse(event.nativeEvent.data) || {};
// console.log('TCL: onWebViewMessage -> msgData', msgData);
// } catch (error) {
// console.error(error);
// return;
// }
// // this[msgData.targetFunc].apply(this, [msgData]);
// };
// /**
// * 영화목록을 받아와서 화면에 전달한다.
// */
// const getMovieList = msgData => {
// webViewRef.current?.postMessage(JSON.stringify(msgData), '*');
// };
const handleDataReceived = (msgData: any) => {
setText(msgData.data);
msgData.isSuccessfull = true;
msgData.args = [msgData.data % 2 ? 'green' : 'red'];
webViewRef.current?.injectJavaScript(
`window.postMessage('${JSON.stringify(msgData)}', '*');`,
);
};
/**
* 화면에서 post를 던지면 react-native에서 받음
*/
const handleMessage = (event: any) => {
console.log('Message received from webview');
let msgData;
try {
msgData = JSON.parse(event.nativeEvent.data);
} catch (err) {
console.warn(err);
return;
}
this[msgData.targetFunc]();
switch (msgData.targetFunc) {
case 'handleDataReceived':
globalThis[msgData.targetFunc]([msgData]);
break;
}
};
return (
<>
<StatusBar />
<Text>{text}</Text>
<WebView
ref={webViewRef}
originWhitelist={['*']}
source={{uri: sampleHtml}}
javaScriptEnabled
onMessage={handleMessage}
/>
</>
);
};
// const styles = StyleSheet.create({
// scrollView: {
// backgroundColor: Colors.lighter,
// },
// engine: {
// position: 'absolute',
// right: 0,
// },
// body: {
// backgroundColor: Colors.white,
// },
// sectionContainer: {
// marginTop: 32,
// paddingHorizontal: 24,
// },
// sectionTitle: {
// fontSize: 24,
// fontWeight: '600',
// color: Colors.black,
// },
// sectionDescription: {
// marginTop: 8,
// fontSize: 18,
// fontWeight: '400',
// color: Colors.dark,
// },
// highlight: {
// fontWeight: '700',
// },
// footer: {
// color: Colors.dark,
// fontSize: 12,
// fontWeight: '600',
// padding: 4,
// paddingRight: 12,
// textAlign: 'right',
// },
// });
export default App;
'문제해결(Trouble shootings)' 카테고리의 다른 글
TS7016: Could not find a declaration file for module 'qs'. '/node_modules/.pnpm/ (0) | 2023.02.08 |
---|---|
TS7016: Could not find a declaration file for module 'prismjs/components/prism-c (0) | 2023.02.08 |
ubuntu 17.10 무료 ssl https certbot letsencrypt 설정 (0) | 2018.05.12 |
ubuntu17.10 certbot https 인증에서 사이트 하나 제거하기 (0) | 2018.05.12 |
MSSql 스토어드 프로시져 사용시에만 Timeout에러. 잘못된게 없는데 에러나는 저장함수 호출 (0) | 2017.05.15 |