Переход назад из стека C в стек B не вызовет componentDidMount (), так как компоненты были уже смонтированы при создании стека B.
, который вы можете сделать, это сбросить стек навигации при переходе из стека B в стек C, как показано ниже.
const stackCAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'StackC' })],
});
диспетчеризация с пометкой
this.props.navigation.dispatch(stackCAction);
, возвращаясь назад, сделать это невозможно.
поочередно вы можете передать функцию обратного вызова из стека B в стек C для обновления.
Проверьте эту ссылку для полного ответа.
I believe what you may be missing is the call to register for device notification. Here is code that I use to do the same thing, though I override the winEvent() method of the QWidget class and not the winEventFilter.
// Register for device connect notification
DEV_BROADCAST_DEVICEINTERFACE devInt;
ZeroMemory( &devInt, sizeof(devInt) );
devInt.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
devInt.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
devInt.dbcc_classguid = GUID_DEVINTERFACE_VOLUME;
m_hDeviceNotify =
RegisterDeviceNotification( winId(), &devInt, DEVICE_NOTIFY_WINDOW_HANDLE );
if(m_hDeviceNotify == NULL)
{
qDebug() << "Failed to register device notification";
} // end if
NOTE: You will most likely need to change the values of the DEV_BROADCAST_DEVICEINTERFACE
to fit your needs.
EDIT: To use this code you will need to include the proper header files and perform the proper setup. DEV_BROADCAST_DEVICEINTERFACE
requires the Dbt.h header to be included. Also, the focal point of this code is on the RegisterDeviceNotification function. Info is available on MSDN
Я работаю по тем же принципам, но на C #.
вам необходимо зарегистрировать приложение в системе (посмотрите на функцию RegisterHidNotification ()). Мой выглядит так: `
void RegisterHidNotification() //Register this application to recieve all USB device notices
{
BroadcastHeader dbi = new BroadcastHeader();
int size = Marshal.SizeOf(dbi);
dbi.Size = size;
dbi.Type = DeviceType.DeviceInterface;
**dbi.Classguid = GUID_DEVINTERFACE_USB_DEVICE**;
dbi.Name = 0;
IntPtr buffer = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(dbi, buffer, true);
IntPtr r = RegisterDeviceNotification(this.Handle, buffer, (int)DeviceEvents.regWindowHandle);
if (r == IntPtr.Zero)
statusLabel.Text = GetLastError().ToString();
}`
Самая важная часть функции - это бит, который я выделил жирным шрифтом (или, по крайней мере, попытался). Определено как: public Guid GUID_DEVINTERFACE_USB_DEVICE = new Guid ("A5DCBF10-6530-11D2-901F-00C04FB951ED");
Надеюсь, вы сможете адаптировать его к своему приложению.