-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(HighContrast): Expose the XAML HighContrastChanged event to JS #1443
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using ReactNative.Bridge; | ||
using ReactNative.Modules.Core; | ||
using System.Collections.Generic; | ||
using Windows.UI.ViewManagement; | ||
|
||
namespace ReactNative.Modules.Accessibilityinfo | ||
{ | ||
class AccessibilityInfoModule : ReactContextNativeModuleBase | ||
{ | ||
private readonly AccessibilitySettings _accessibility = new AccessibilitySettings(); | ||
private readonly UISettings _settings = new UISettings(); | ||
|
||
private string GetRgbaString(UIElementType type) | ||
{ | ||
var color = _settings.UIElementColor(type); | ||
return "rgba(" + color.R + "," + color.G + "," + color.B + "," + color.A + ")"; | ||
} | ||
|
||
private IDictionary<string, string> GetHighContrastColors() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe put a TODO about how we want to expose these colors to JavaScript in the future There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
{ | ||
return new Dictionary<string, string> | ||
{ | ||
{ "windowText", GetRgbaString(UIElementType.WindowText) }, | ||
{ "hotlight", GetRgbaString(UIElementType.Hotlight) }, | ||
{ "grayText", GetRgbaString(UIElementType.GrayText) }, | ||
{ "highlightText", GetRgbaString(UIElementType.HighlightText) }, | ||
{ "highlight", GetRgbaString(UIElementType.Highlight) }, | ||
{ "buttonText", GetRgbaString(UIElementType.ButtonText) }, | ||
{ "buttonFace", GetRgbaString(UIElementType.ButtonFace) }, | ||
{ "window", GetRgbaString(UIElementType.Window) }, | ||
}; | ||
} | ||
|
||
public AccessibilityInfoModule(ReactContext reactContext) | ||
: base(reactContext) | ||
{ | ||
|
||
} | ||
|
||
public override string Name => "AccessibilityInfo"; | ||
|
||
public override IReadOnlyDictionary<string, object> Constants | ||
{ | ||
get | ||
{ | ||
return new Dictionary<string, object> | ||
{ | ||
// TODO: It would be better to have a sync GethIsHighContrast, | ||
// but this is not supported by the framework at the moment. | ||
{ "initialHighContrast", _accessibility.HighContrast }, | ||
}; | ||
} | ||
} | ||
|
||
public override void Initialize() | ||
{ | ||
_accessibility.HighContrastChanged += OnHighContrastChanged; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Should we do this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eric suggested to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. What's the reasoning behind preferring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constructor is called before the JS bundle is loaded, so you could potentially notify event to JS before anything there to listen. If you call after Initialize, bundle load operation has already been queued. In reply to: 144430206 [](ancestors = 144430206) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Firing an event before anything is listening sounds pretty harmless. So it sounds like it doesn't matter too much whether you register for the event in In reply to: 145428282 [](ancestors = 145428282,144430206) |
||
} | ||
|
||
public override void OnReactInstanceDispose() | ||
{ | ||
_accessibility.HighContrastChanged -= OnHighContrastChanged; | ||
} | ||
|
||
private void OnHighContrastChanged(AccessibilitySettings sender, object args) | ||
{ | ||
Context.GetJavaScriptModule<RCTDeviceEventEmitter>() | ||
.emit("highContrastDidChange", sender.HighContrast); | ||
} | ||
|
||
[ReactMethod] | ||
public void fetchIsHighContrast(IPromise promise) | ||
{ | ||
promise.Resolve(_accessibility.HighContrast); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put a comment about how UWP doesn't provide any way to query whether or not a screen reader is being used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done