<commit_before>// @flow
import * as React from 'react'
import {WebView} from 'react-native'
import type {WebViewInjections, WebViewProps} from './web-view'
import {memoize} from 'lodash-es'

const escape = (str?: string): string => (str ? str.replace(/\\/g, '\\\\').replace(/`/g, '\\`') : '')

const combineJavaScriptAndCSS = (injections?: WebViewInjections) =>
  !injections
    ? ''
    : `
(function() {
  const style = document.createElement('style')
  document.body.appendChild(style)
  style.type = 'text/css'
  style.appendChild(document.createTextNode(\`${escape(injections.css)}\`))
})()

(function() {\` ${escape(injections.javaScript)} \`})()
`

const KBWebView = (props: WebViewProps) => {
  const {onLoadingStateChange} = props
  return (
    <WebView
      useWebKit={true}
      source={{uri: props.url}}
      injectedJavaScript={memoize(combineJavaScriptAndCSS)(props.injections)}
      style={props.style}
      onLoadStart={onLoadingStateChange && (() => onLoadingStateChange(true))}
      onLoadEnd={onLoadingStateChange && (() => onLoadingStateChange(false))}
    />
  )
}

export default KBWebView<commit_msg>fix inline video playback (#13731)<commit_after>// @flow
import * as React from 'react'
import {WebView} from 'react-native'
import type {WebViewInjections, WebViewProps} from './web-view'
import {memoize} from 'lodash-es'

const escape = (str?: string): string => (str ? str.replace(/\\/g, '\\\\').replace(/`/g, '\\`') : '')

const combineJavaScriptAndCSS = (injections?: WebViewInjections) =>
  !injections
    ? ''
    : `
(function() {
  const style = document.createElement('style')
  document.body.appendChild(style)
  style.type = 'text/css'
  style.appendChild(document.createTextNode(\`${escape(injections.css)}\`))
})()

(function() {\` ${escape(injections.javaScript)} \`})()
`

const KBWebView = (props: WebViewProps) => {
  const {onLoadingStateChange} = props
  return (
    <WebView
      allowsInlineMediaPlayback={true}
      useWebKit={true}
      source={{uri: props.url}}
      injectedJavaScript={memoize(combineJavaScriptAndCSS)(props.injections)}
      style={props.style}
      onLoadStart={onLoadingStateChange && (() => onLoadingStateChange(true))}
      onLoadEnd={onLoadingStateChange && (() => onLoadingStateChange(false))}
    />
  )
}

export default KBWebView
{'fraction_non_alphanumeric': 0.17657192075796727, 'fraction_numerical': 0.002153316106804479, 'mean_word_length': 4.402325581395349, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3820438', 'n_tokens_mistral': 759, 'n_tokens_neox': 741, 'n_words': 134}