import React from 'react'
import { requireNativeComponent, ViewProps, findNodeHandle } from 'react-native'
import { UIManagerHelper } from './utils';

const NATIVE_COMPONENT_NAME = "CallPreview"
const NTiveView = requireNativeComponent(NATIVE_COMPONENT_NAME)
interface PreviewProps extends ViewProps {
    parentNode?: number
}
class Preview extends React.PureComponent<PreviewProps> {

    componentDidMount() {
        this.addRenderer()
    }

    addRenderer = () => {
        UIManagerHelper.dispatchViewMethod(
            this,
            NATIVE_COMPONENT_NAME,
            "addRenderer",
            [findNodeHandle(this.props.parentNode!)]
        )
    }

    render() {
        return (
            <NTiveView
                {...this.props}
            />
        )
    }
}

export default Preview