fix: support both addListener and addEventListener

This commit is contained in:
Christopher Willis-Ford committed 2023-07-05 13:43:02 -07:00
1 parent 0b449dc5d5
commit aeb7617fdf
1 file changed
+10 -2
+10 -2
View File
@@ -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);
}
}
}