{"id":15104,"date":"2024-08-30T10:52:41","date_gmt":"2024-08-30T01:52:41","guid":{"rendered":"https:\/\/www.ecomottblog.com\/?p=15104"},"modified":"2024-08-30T10:52:41","modified_gmt":"2024-08-30T01:52:41","slug":"react-native%e3%81%abhtml%e3%82%b3%e3%83%bc%e3%83%89%e3%82%92%e6%b7%b7%e3%81%9c%e3%81%a6%e3%81%bf%e3%81%9f%e8%a9%b1","status":"publish","type":"post","link":"https:\/\/www.ecomottblog.com\/?p=15104","title":{"rendered":"React Native\u306bHTML\u30b3\u30fc\u30c9\u3092\u6df7\u305c\u3066\u307f\u305f\u8a71"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01<br \/>\n\u30af\u30e9\u30a6\u30c9\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u90e8\u306e\u5927\u5ddd\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3001React Native\u3067HTML\u30b3\u30fc\u30c9\u3092\u6df7\u305c\u3066\u4f7f\u3063\u3066\u307f\u305f\u8a71\u3092\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\uff01<br \/>\n\u300c\u3048\u3063\u3001\u30cd\u30a4\u30c6\u30a3\u30d6\u30a2\u30d7\u30ea\u306bHTML\u3092\u6df7\u305c\u308b\u3063\u3066\u3069\u3046\u3044\u3046\u3053\u3068\uff1f\u300d\u3068\u601d\u3063\u305f\u65b9\u3001\u5b9f\u306f\u3053\u308c\u304c\u3068\u3066\u3082\u4fbf\u5229\u306a\u3093\u3067\u3059\u3088\u30fb\u30fb\u30fb\uff01<br \/>\n\u3067\u306f\u65e9\u901f\u3001\u305d\u306e\u4f53\u9a13\u8ac7\u3092\u304a\u5c4a\u3051\u3057\u307e\u3059\uff01<\/p>\n<p><!--more--><\/p>\n<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p>React Native\u3067\u958b\u767a\u3092\u9032\u3081\u3066\u3044\u308b\u3068\u3001\u300c\u3053\u306eWeb\u30da\u30fc\u30b8\u3001\u30a2\u30d7\u30ea\u306e\u4e00\u90e8\u3068\u3057\u3066\u305d\u306e\u307e\u307e\u4f7f\u3048\u305f\u3089\u4fbf\u5229\u306a\u306e\u306b\u2026\u300d\u3068\u601d\u3046\u77ac\u9593\u304c\u3042\u308a\u307e\u305b\u3093\u304b\uff1f<br \/>\n\u305d\u308c\u304c\u3067\u304d\u308b\u306e\u304c\u3001\u307e\u3055\u306breact-native-webview\u306a\u3093\u3067\u3059\u3002\u3053\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001Web\u30da\u30fc\u30b8\u3084HTML\u30b3\u30f3\u30c6\u30f3\u30c4\u3092React Native\u30a2\u30d7\u30ea\u306b\u30b7\u30fc\u30e0\u30ec\u30b9\u306b\u7d44\u307f\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u306a\u305cHTML\u3092\u6df7\u305c\u308b\u306e\u304b\uff1f<\/h2>\n<p>\u307e\u305a\u3001\u305d\u3082\u305d\u3082\u300c\u306a\u305cHTML\u3092\u6df7\u305c\u308b\u306e\u304b\uff1f\u300d\u3068\u3044\u3046\u7591\u554f\u304c\u6d6e\u304b\u3076\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u7406\u7531\u306f\u30b7\u30f3\u30d7\u30eb\u3067\u3001<strong><span style=\"color: red; \">\u65e2\u5b58\u306eWeb\u30b3\u30f3\u30c6\u30f3\u30c4\u3084\u52d5\u7684\u306a\u30da\u30fc\u30b8\u3092\u518d\u5229\u7528\u3057\u305f\u3044\u304b\u3089<\/span><\/strong>\u3067\u3059\uff01\uff01<br \/>\n\u4f8b\u3048\u3070\u3001\u65e2\u306b\u5b58\u5728\u3059\u308b\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u30da\u30fc\u30b8\u3084\u30d6\u30ed\u30b0\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u3001\u30a2\u30d7\u30ea\u5185\u306b\u305d\u306e\u307e\u307e\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308c\u3070\u3001\u958b\u767a\u306e\u624b\u9593\u3092\u5927\u5e45\u306b\u524a\u6e1b\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3067\u3082\u3001\u300c\u305d\u308c\u306a\u3089Web\u30a2\u30d7\u30ea\u3067\u3044\u3044\u3093\u3058\u3083\u306a\u3044\uff1f\u300d\u3068\u601d\u3046\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<br \/>\n\u3057\u304b\u3057\u3001\u30cd\u30a4\u30c6\u30a3\u30d6\u30a2\u30d7\u30ea\u306e\u9b45\u529b\u306f\u3001\u30ab\u30e1\u30e9\u3084GPS\u3001\u901a\u77e5\u306a\u3069\u3001\u30c7\u30d0\u30a4\u30b9\u306e\u6a5f\u80fd\u3092\u30d5\u30eb\u306b\u6d3b\u7528\u3067\u304d\u308b\u70b9\u306b\u3042\u308a\u307e\u3059\u3002<br \/>\n\u305d\u3053\u3067\u3001\u3053\u306e\u4e8c\u3064\u306e\u4e16\u754c\u3092\u878d\u5408\u3055\u305b\u305f\u300c\u30cf\u30a4\u30d6\u30ea\u30c3\u30c9\u30a2\u30d7\u30ed\u30fc\u30c1\u300d\u304c\u767b\u5834\u3057\u307e\u3059\u3002<\/p>\n<p>WebView\u306bJavaScript\u3092\u57cb\u3081\u8fbc\u3080\u3053\u3068\u3067\u3001Web\u30da\u30fc\u30b8\u3068\u30cd\u30a4\u30c6\u30a3\u30d6\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u76f8\u4e92\u306b\u3084\u308a\u53d6\u308a\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u3001\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u30cd\u30a4\u30c6\u30a3\u30d6\u306e\u30a2\u30af\u30b7\u30e7\u30f3\u3092\u30c8\u30ea\u30ac\u30fc\u3057\u305f\u308a\u3001\u30a2\u30d7\u30ea\u304b\u3089Web\u30da\u30fc\u30b8\u306b\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3059\u308b\u306a\u3069\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\uff01<\/p>\n<pre><code>import React, {useRef, useState} from 'react';\nimport {Alert, SafeAreaView, StyleSheet, Text, View} from 'react-native';\nimport {TextInput} from 'react-native-gesture-handler';\nimport WebView from 'react-native-webview';\n\nconst DebugScreen = () =&gt; {\n  const [text, setText] = useState('React Native\u5185\u306e\u30c6\u30ad\u30b9\u30c8');\n\n  var htmlContent = `\n   &lt;html&gt;\n      &lt;head&gt;\n          &lt;meta charset=\"UTF-8\" \/&gt;\n          &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" \/&gt;\n      &lt;\/head&gt;\n      &lt;body&gt;\n        &lt;h1 style=\"color: blue;\"&gt;\u3053\u308c\u306fHTML\u3067\u3059&lt;\/h1&gt;\n        &lt;p&gt;Web\u306e\u4e16\u754c\u3068\u30cd\u30a4\u30c6\u30a3\u30d6\u306e\u4e16\u754c\u3092\u878d\u5408\u3057\u307e\u3057\u305f\uff01&lt;\/p&gt;\n        &lt;button onclick=\"alert('\u30dc\u30bf\u30f3\u304c\u30af\u30ea\u30c3\u30af\u3055\u308c\u307e\u3057\u305f\uff01')\"&gt;HTML\u3067\u30a2\u30e9\u30fc\u30c8\u3092\u8868\u793a&lt;\/button&gt;\n        &lt;button onclick=\"sendReactNative()\"&gt;React Native\u306b\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3059\u308b&lt;\/button&gt;\n      &lt;\/body&gt;\n    &lt;\/html&gt;\n    &lt;style&gt;\n      html {\n        background-color: #cffcfb;\n      }\n      button {\n        margin: 10px;\n        padding: 10px;\n        background-color: #f0f0f0;\n        border: 1px solid #000;\n        border-radius: 5px;\n        cursor: pointer;\n      }\n    &lt;\/style&gt;\n    &lt;script&gt;\n      function sendReactNative() {\n        window.ReactNativeWebView.postMessage('Webview\u304b\u3089React Native\u306b\u30c7\u30fc\u30bf\u3092\u9001\u4fe1\u3057\u307e\u3057\u305f\uff01');\n      }\n    &lt;\/script&gt;\n  `;\n\n  const webview = useRef(null);\n\n  const _handleMessage = event =&gt; {\n    \/\/ \u3053\u3053\u3067Webview\u304b\u3089\u9001\u3089\u308c\u3066\u304d\u305f\u5024\u3092React Native\u5074\u3067\u53d7\u3051\u53d6\u308b\n    setText(event.nativeEvent.data);\n  };\n\n  const ReactNativeComponent = () =&gt; {\n    return (\n      &lt;View style={{marginTop: 30}}&gt;\n        &lt;Text&gt;React Native\u5185\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8&lt;\/Text&gt;\n        &lt;TextInput value={text} style={{borderWidth: 1, borderColor: 'black', backgroundColor: '#FFFFFF', padding: 10, margin: 10}} \/&gt;\n      &lt;\/View&gt;\n    );\n  };\n\n  return (\n    &lt;SafeAreaView style={styles.webviewContainer}&gt;\n      &lt;View style={styles.container}&gt;\n        &lt;WebView\n          source={{html: htmlContent}}\n          originWhitelist={['*']}\n          allowsInlineMediaPlayback={true}\n          mediaPlaybackRequiresUserAction={false}\n          scrollEnabled={false}\n          scalesPageToFit={true}\n          useWebKit={true}\n          javaScriptCanOpenWindowsAutomatically\n          ref={webview}\n          onMessage={_handleMessage}\n          overScrollMode={'never'}\n        \/&gt;\n        &lt;ReactNativeComponent \/&gt;\n      &lt;\/View&gt;\n    &lt;\/SafeAreaView&gt;\n  );\n};\n\nconst styles = StyleSheet.create({\n  container: {\n    flex: 1,\n  },\n  webviewContainer: {\n    flex: 0.5,\n  },\n});\n\nexport default DebugScreen;\n<\/code><\/pre>\n<div style=\"width: 240px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-15104-1\" width=\"240\" height=\"320\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.ecomottblog.com\/wp-content\/uploads\/2024\/08\/react-native-webview.mp4?_=1\" \/><a href=\"https:\/\/www.ecomottblog.com\/wp-content\/uploads\/2024\/08\/react-native-webview.mp4\">https:\/\/www.ecomottblog.com\/wp-content\/uploads\/2024\/08\/react-native-webview.mp4<\/a><\/video><\/div>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>React Native\u306bHTML\u30b3\u30fc\u30c9\u3092\u6df7\u305c\u308b\u3053\u3068\u3067\u3001\u30a2\u30d7\u30ea\u958b\u767a\u306b\u65b0\u305f\u306a\u53ef\u80fd\u6027\u304c\u5e83\u304c\u308a\u307e\u3059\u3002<br \/>\n\u65e2\u5b58\u306eWeb\u8cc7\u7523\u3092\u6709\u52b9\u6d3b\u7528\u3057\u306a\u304c\u3089\u3001\u30cd\u30a4\u30c6\u30a3\u30d6\u30a2\u30d7\u30ea\u306a\u3089\u3067\u306f\u306e\u6a5f\u80fd\u3092\u6d3b\u304b\u305b\u308b\u3001\u3053\u306e\u30a2\u30d7\u30ed\u30fc\u30c1\u3001\u305c\u3072\u7686\u3055\u3093\u3082\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\uff01<\/p>\n<h2>\u7d42\u308f\u308a\u306b<\/h2>\n<p>\u30a8\u30b3\u30e2\u30c3\u30c8\u3067\u306f\u4e00\u7dd2\u306b\u30e2\u30ce\u3065\u304f\u308a\u3092\u3057\u3066\u3044\u304f\u4ef2\u9593\u3092\u52df\u96c6\u4e2d\u3067\u3059\uff01<br \/>\n\u5f0a\u793e\u306b\u5c11\u3057\u3067\u3082\u8208\u5473\u304c\u3042\u308b\u65b9\u3001\u305c\u3072\u4e0b\u8a18\u306e\u63a1\u7528\u30da\u30fc\u30b8\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\uff01<\/p>\n<p><a href=\"https:\/\/www.ecomott.co.jp\/recruit\/\">\u52df\u96c6\u8981\u9805\uff08\u5f53\u793eHP\uff09<\/a><br \/>\n<a href=\"https:\/\/www.wantedly.com\/companies\/ecomott2\/projects\">Wantedly<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01 \u30af\u30e9\u30a6\u30c9\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u90e8\u306e\u5927\u5ddd\u3067\u3059\u3002 \u4eca\u56de\u306f\u3001React Native\u3067HTML\u30b3\u30fc\u30c9\u3092\u6df7\u305c\u3066\u4f7f\u3063\u3066\u307f\u305f\u8a71\u3092\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\uff01 \u300c\u3048\u3063\u3001\u30cd\u30a4\u30c6\u30a3\u30d6\u30a2\u30d7\u30ea\u306bHTML\u3092\u6df7\u305c\u308b\u3063\u3066\u3069\u3046\u3044\u3046\u3053\u3068\uff1f\u300d\u3068\u601d\u3063\u305f [&hellip;]<\/p>\n","protected":false},"author":36,"featured_media":15122,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[26,103,175,242,184],"_links":{"self":[{"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/15104"}],"collection":[{"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15104"}],"version-history":[{"count":16,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/15104\/revisions"}],"predecessor-version":[{"id":15121,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/15104\/revisions\/15121"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/media\/15122"}],"wp:attachment":[{"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}