import React, { forwardRef, ForwardRefRenderFunction, useImperativeHandle, useRef, } from 'react'; import { findNodeHandle, requireNativeComponent, StyleProp, UIManager, ViewStyle, } from 'react-native'; export enum ShippedSuiteType { Shield, Green, GreenAndShield, } export enum ShippedSuiteAppearance { Auto, Light, Dark, } export type ShippedSuiteConfiguration = { type?: ShippedSuiteType; isInformational?: boolean; isMandatory?: boolean; isRespectServer?: boolean; currency?: string; appearance?: ShippedSuiteAppearance; }; export interface WidgetViewProps { style?: StyleProp; ref?: any; configuration: ShippedSuiteConfiguration; onChange: (values: any) => void; } export type WidgetViewMethods = { updateOrderValue: (amount: string) => void; }; export interface WidgetChangeEventData { isSelected: boolean; totalFee?: string; error?: string; } const RNWidgetView = requireNativeComponent('RNWidgetView'); const _WidgetView: ForwardRefRenderFunction< WidgetViewMethods, WidgetViewProps > = (props, ref) => { const { configuration, onChange, ...others } = props; const widgetRef = useRef(null); const updateOrderValue = (amount: string) => { UIManager.dispatchViewManagerCommand( findNodeHandle(widgetRef.current), 'updateOrderValue' as any, [amount] ); }; useImperativeHandle( ref, () => ({ updateOrderValue, }), [] ); return ( ); }; export const WidgetView = forwardRef(_WidgetView);