mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
iOS implementation of sendAccessibilityEvent
Summary: This is the iOS native implementation of sendAccessibilityEvent for Fabric. Changelog: [Internal] Reviewed By: shergin Differential Revision: D25857401 fbshipit-source-id: e57d2e7fd45052bcf05cee7d0cb6c55ee974f358
This commit is contained in:
committed by
Facebook GitHub Bot
parent
055d029bc0
commit
e3a05c9e3e
@@ -38,6 +38,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
*/
|
||||
- (void)dispatchCommand:(ReactTag)reactTag commandName:(NSString *)commandName args:(NSArray *)args;
|
||||
|
||||
/**
|
||||
* Dispatch an accessibility event to be performed on the main thread.
|
||||
* Can be called from any thread.
|
||||
*/
|
||||
- (void)sendAccessibilityEvent:(ReactTag)reactTag eventType:(NSString *)eventType;
|
||||
|
||||
- (void)synchronouslyUpdateViewOnUIThread:(ReactTag)reactTag
|
||||
changedProps:(NSDictionary *)props
|
||||
componentDescriptor:(const facebook::react::ComponentDescriptor &)componentDescriptor;
|
||||
|
||||
@@ -180,6 +180,22 @@ static void RCTPerformMountInstructions(
|
||||
});
|
||||
}
|
||||
|
||||
- (void)sendAccessibilityEvent:(ReactTag)reactTag eventType:(NSString *)eventType
|
||||
{
|
||||
if (RCTIsMainQueue()) {
|
||||
// Already on the proper thread, so:
|
||||
// * No need to do a thread jump;
|
||||
// * No need to allocate a block.
|
||||
[self synchronouslyDispatchAccessbilityEventOnUIThread:reactTag eventType:eventType];
|
||||
return;
|
||||
}
|
||||
|
||||
RCTExecuteOnMainQueue(^{
|
||||
RCTAssertMainQueue();
|
||||
[self synchronouslyDispatchAccessbilityEventOnUIThread:reactTag eventType:eventType];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)initiateTransaction:(MountingCoordinator::Shared const &)mountingCoordinator
|
||||
{
|
||||
SystraceSection s("-[RCTMountingManager initiateTransaction:]");
|
||||
@@ -257,4 +273,12 @@ static void RCTPerformMountInstructions(
|
||||
[componentView handleCommand:commandName args:args];
|
||||
}
|
||||
|
||||
- (void)synchronouslyDispatchAccessbilityEventOnUIThread:(ReactTag)reactTag eventType:(NSString *)eventType
|
||||
{
|
||||
if ([@"focus" isEqualToString:eventType]) {
|
||||
UIView<RCTComponentViewProtocol> *componentView = [_componentViewRegistry findComponentViewWithTag:reactTag];
|
||||
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, componentView);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -31,6 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
commandName:(std::string const &)commandName
|
||||
args:(folly::dynamic const)args;
|
||||
|
||||
- (void)schedulerDidSendAccessibilityEvent:(facebook::react::ShadowView const &)shadowView
|
||||
eventType:(std::string const &)eventType;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,6 +59,12 @@ class SchedulerDelegateProxy : public SchedulerDelegate {
|
||||
// Does nothing for now.
|
||||
}
|
||||
|
||||
void schedulerDidSendAccessibilityEvent(const ShadowView &shadowView, std::string const &eventType) override
|
||||
{
|
||||
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
|
||||
[scheduler.delegate schedulerDidSendAccessibilityEvent:shadowView eventType:eventType];
|
||||
}
|
||||
|
||||
private:
|
||||
void *scheduler_;
|
||||
};
|
||||
|
||||
@@ -465,6 +465,15 @@ static BackgroundExecutor RCTGetBackgroundExecutor()
|
||||
[self->_mountingManager dispatchCommand:tag commandName:commandStr args:argsArray];
|
||||
}
|
||||
|
||||
- (void)schedulerDidSendAccessibilityEvent:(const facebook::react::ShadowView &)shadowView
|
||||
eventType:(const std::string &)eventType
|
||||
{
|
||||
ReactTag tag = shadowView.tag;
|
||||
NSString *eventTypeStr = [[NSString alloc] initWithUTF8String:eventType.c_str()];
|
||||
|
||||
[self->_mountingManager sendAccessibilityEvent:tag eventType:eventTypeStr];
|
||||
}
|
||||
|
||||
- (void)addObserver:(id<RCTSurfacePresenterObserver>)observer
|
||||
{
|
||||
std::unique_lock<better::shared_mutex> lock(_observerListMutex);
|
||||
|
||||
Reference in New Issue
Block a user