fix: support both addListener and addEventListener
This commit is contained in:
1 parent
0b449dc5d5
commit
aeb7617fdf
1 file changed
+10
-2
@@ -17,14 +17,22 @@ const systemPreferencesHOC = function (WrappedComponent) {
|
||||
if (window.matchMedia) {
|
||||
this.highContrastMatchMedia = window.matchMedia(prefersHighContrastQuery);
|
||||
if (this.highContrastMatchMedia) {
|
||||
this.highContrastMatchMedia.addEventListener('change', this.preferencesListener);
|
||||
if (this.highContrastMatchMedia.addEventListener) {
|
||||
this.highContrastMatchMedia.addEventListener('change', this.preferencesListener);
|
||||
} else {
|
||||
this.highContrastMatchMedia.addListener(this.preferencesListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
if (this.highContrastMatchMedia) {
|
||||
this.highContrastMatchMedia.removeEventListener('change', this.preferencesListener);
|
||||
if (this.highContrastMatchMedia.removeEventListener) {
|
||||
this.highContrastMatchMedia.removeEventListener('change', this.preferencesListener);
|
||||
} else {
|
||||
this.highContrastMatchMedia.removeListener(this.preferencesListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user