From b888e8db40918c9d7c206784a03e7d7614959f24 Mon Sep 17 00:00:00 2001 From: Dorota Kapturkiewicz Date: Thu, 20 Aug 2015 07:43:29 -0700 Subject: [PATCH] [ReactNative] make sending accessibility events from JS possible and fix dialog --- Libraries/Portal/Portal.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Libraries/Portal/Portal.js b/Libraries/Portal/Portal.js index a029bb99f..7406fb63f 100644 --- a/Libraries/Portal/Portal.js +++ b/Libraries/Portal/Portal.js @@ -6,7 +6,9 @@ */ 'use strict'; +var Platform = require('Platform'); var React = require('React'); +var RCTUIManager = require('NativeModules').UIManager; var StyleSheet = require('StyleSheet'); var View = require('View'); @@ -72,7 +74,15 @@ var Portal = React.createClass({ return []; } return _portalRef._getOpenModals(); - } + }, + + notifyAccessibilityService: function() { + if (!_portalRef) { + console.error('Calling closeModal but no Portal has been rendered.'); + return; + } + _portalRef._notifyAccessibilityService(); + }, }, getInitialState: function() { @@ -106,6 +116,20 @@ var Portal = React.createClass({ return Object.keys(this.state.modals); }, + _notifyAccessibilityService: function() { + if (Platform.OS === 'android') { + // We need to send accessibility event in a new batch, as otherwise + // TextViews have no text set at the moment of populating event. + setTimeout(() => { + if (this._getOpenModals().length > 0) { + RCTUIManager.sendAccessibilityEvent( + React.findNodeHandle(this), + RCTUIManager.AccessibilityEventTypes.typeWindowStateChanged); + } + }, 0); + } + }, + render: function() { _portalRef = this; if (!this.state.modals) { @@ -119,7 +143,9 @@ var Portal = React.createClass({ return null; } return ( - + {modals} );