diff --git a/packages/connect-examples/expo-example/src/components/DeviceList.tsx b/packages/connect-examples/expo-example/src/components/DeviceList.tsx index d78ed00fa..a789675bf 100644 --- a/packages/connect-examples/expo-example/src/components/DeviceList.tsx +++ b/packages/connect-examples/expo-example/src/components/DeviceList.tsx @@ -80,7 +80,7 @@ const Item = ({ item, onPress, connected }: ItemProps) => { }; type IDeviceListProps = { - onSelected: (device: Device) => void; + onSelected: (device: Device | undefined) => void; disableSaveDevice?: boolean; }; export interface IDeviceListInstance { @@ -108,15 +108,16 @@ function DeviceListFC( }, []); const selectDevice = useCallback( - (device: Device) => { - setSelectedId(device.connectId); - storeSelectedId(device.connectId); + (device: Device | undefined) => { + setSelectedId(device?.connectId ?? ''); + storeSelectedId(device?.connectId ?? ''); onSelected(device); }, [onSelected] ); const searchDevices = useCallback(async () => { + selectDevice(undefined); if (!sdk) return alert(intl.formatMessage({ id: 'tip__sdk_not_ready' })); const response = await sdk.searchDevices(); diff --git a/packages/connect-examples/expo-example/src/views/FirmwareScreen/index.tsx b/packages/connect-examples/expo-example/src/views/FirmwareScreen/index.tsx index 79f33987d..eb9791abc 100644 --- a/packages/connect-examples/expo-example/src/views/FirmwareScreen/index.tsx +++ b/packages/connect-examples/expo-example/src/views/FirmwareScreen/index.tsx @@ -110,7 +110,7 @@ function FirmwareLocalFile({ title, type, onUpdate }: FirmwareLocalFileProps) { } interface FirmwareUpdateProps { - selectDevice: Device | null; + selectDevice: Device | undefined; onReconnectDevice: () => void; onDisconnectDevice: () => void; } @@ -150,7 +150,12 @@ function FirmwareUpdate({ useEffect(() => { if (!sdk) return; - if (selectDevice?.connectId == null && selectDevice?.features == null) return; + if (selectDevice?.connectId == null || selectDevice?.features == null) { + setFeatures(undefined); + setOnekeyFeatures(undefined); + return; + } + setConnecting(true); setFeatures(undefined); sdk @@ -393,7 +398,7 @@ function FirmwareUpdate({ } export default function FirmwareScreen() { - const [selectedDevice, setSelectedDevice] = useState(null); + const [selectedDevice, setSelectedDevice] = useState(undefined); const deviceListInstanceRef = useRef(null); return ( @@ -402,9 +407,8 @@ export default function FirmwareScreen() { setSelectedDevice(null)} + onDisconnectDevice={() => setSelectedDevice(undefined)} onReconnectDevice={() => { - setSelectedDevice(null); deviceListInstanceRef.current?.searchDevices(); }} />