Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.9 KB
Raw Blame
import { memo, useMemo } from 'react'
import { StyleSheet, View } from 'react-native'
import { buildNativeChatVisualDocument } from '../../../../../src/shared/native-chat/native-chat-visual-shell'
import type { MobileNativeChatVisualHostMode } from './mobile-native-chat-visual-host-document'
import { MOBILE_NATIVE_CHAT_VISUAL_THEME } from './mobile-native-chat-visual-theme'
import { useMobileColorScheme } from '../../../theme/use-mobile-color-scheme'

export type MobileNativeChatVisualFrameProps = {
  html: string
  title: string
  mode: MobileNativeChatVisualHostMode
  onFailed: () => void
}

// Sealed frames run no script to report height; use an internally scrolling fixed-height frame.
const SEALED_INLINE_HEIGHT = 320

// srcdoc inherits shell CSP, so keep visuals static and sandboxed with opaque origin; enabling inline scripts would weaken page policy.
export const MobileNativeChatVisualFrame = memo(function MobileNativeChatVisualFrame({
  html,
  title,
  mode
}: MobileNativeChatVisualFrameProps) {
  const colorScheme = useMobileColorScheme()
  const document = useMemo(
    () =>
      buildNativeChatVisualDocument({
        html,
        channel: 'sealed',
        theme: MOBILE_NATIVE_CHAT_VISUAL_THEME
      }),
    // Sealed frames run no script, so a scheme rebuild loses no state.
    [html, colorScheme]
  )
  return (
    <View style={mode === 'inline' ? styles.inline : styles.fullscreen}>
      <iframe
        title={title}
        sandbox=""
        srcDoc={document}
        referrerPolicy="no-referrer"
        style={IFRAME_STYLE}
      />
    </View>
  )
})

// Use DOM styles because this is an iframe, not a React Native view.
const IFRAME_STYLE = {
  border: 'none',
  width: '100%',
  height: '100%',
  backgroundColor: 'transparent'
} as const

const styles = StyleSheet.create({
  inline: { width: '100%', height: SEALED_INLINE_HEIGHT },
  fullscreen: { flex: 1 }
})