Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,49 @@ const Text: React.AbstractComponent<
const _hasOnPressOrOnLongPress =
props.onPress != null || props.onLongPress != null;

let retryAnnouncement;
// the event listener detects if VoiceOver announcement fails
AccessibilityInfo.addEventListener(
'announcementFinished',
({announcement, success}) => {
if (!success && retryAnnouncement == null) {
retryAnnouncement = announcement;
console.log('retry announcement');
console.log('announcement:', announcement);
AccessibilityInfo.announceForAccessibility(announcement);
}
if (success && retryAnnouncement === announcement) {
console.log('announcement succed, clear retryAnnouncement');
console.log('announcement:', announcement);
retryAnnouncement = null;
}

if (!success && retryAnnouncement !== announcement) {
console.log(
'skip retry announcement for ' +
announcement +
'as another announcement failed and we try only 1 per time',
);
}
},
);

// trigger voiceover announcement when text changes
React.useEffect(() => {
if (
Platform.OS === 'ios' &&
restProps.accessibilityLiveRegion != null &&
restProps.accessibilityLiveRegion !== 'none' &&
typeof restProps.children === 'string'
) {
const queue = restProps.accessibilityLiveRegion === 'polite';
AccessibilityInfo.announceForAccessibilityWithOptions(
restProps.children,
{queue},
);
}
}, [restProps.children]);

return hasTextAncestor ? (
<NativeVirtualText
{...restProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ - (void)updateState:(State::Shared const &)state oldState:(State::Shared const &
attrsDictionary[UIAccessibilitySpeechAttributeQueueAnnouncement] = @(accessibilityProps.accessibilityLiveRegion == AccessibilityLiveRegion::Polite ? YES : NO);
NSAttributedString *announcementWithAttrs = [[NSAttributedString alloc] initWithString: self.accessibilityLabel
attributes:attrsDictionary];

dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 0.5);
dispatch_after(delay, dispatch_get_main_queue(), ^(void){
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, announcementWithAttrs);
// UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, announcementWithAttrs);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &

dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 0.5);
dispatch_after(delay, dispatch_get_main_queue(), ^(void){
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, announcementWithAttrs);
// UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, announcementWithAttrs);
});
}
}
Expand Down