From 55c2ce902cc06f58247321c54b62d547efd60316 Mon Sep 17 00:00:00 2001 From: etoledom Date: Mon, 26 Aug 2019 08:48:55 +0200 Subject: [PATCH 1/5] Fix MaxListenersExceededWarning caused by dark-mode event emitter --- packages/components/src/mobile/dark-mode/index.native.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/components/src/mobile/dark-mode/index.native.js b/packages/components/src/mobile/dark-mode/index.native.js index b28e64f50d5441..cdbf00b73aa0b5 100644 --- a/packages/components/src/mobile/dark-mode/index.native.js +++ b/packages/components/src/mobile/dark-mode/index.native.js @@ -4,6 +4,8 @@ import { eventEmitter, initialMode } from 'react-native-dark-mode'; import React from 'react'; +eventEmitter.setMaxListeners( 150 ); + export function useStyle( light, dark, theme ) { const finalDark = { ...light, From 8d6942fa98cb80adb23409b4541a1c05ac3dfa27 Mon Sep 17 00:00:00 2001 From: etoledom Date: Mon, 26 Aug 2019 09:53:21 +0200 Subject: [PATCH 2/5] Checking for setMaxListeners trying to avoid CI error --- packages/components/src/mobile/dark-mode/index.native.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/components/src/mobile/dark-mode/index.native.js b/packages/components/src/mobile/dark-mode/index.native.js index cdbf00b73aa0b5..9f36c7a28e453d 100644 --- a/packages/components/src/mobile/dark-mode/index.native.js +++ b/packages/components/src/mobile/dark-mode/index.native.js @@ -4,7 +4,10 @@ import { eventEmitter, initialMode } from 'react-native-dark-mode'; import React from 'react'; -eventEmitter.setMaxListeners( 150 ); +// This was failing on CI +if ( eventEmitter.setMaxListeners ) { + eventEmitter.setMaxListeners( 150 ); +} export function useStyle( light, dark, theme ) { const finalDark = { From 1380ab6c53d60335f99f778ebb4ab9043de7190f Mon Sep 17 00:00:00 2001 From: etoledom Date: Mon, 26 Aug 2019 11:12:11 +0200 Subject: [PATCH 3/5] Adding remove listener to DarkMode HOC --- .../components/src/mobile/dark-mode/index.native.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/components/src/mobile/dark-mode/index.native.js b/packages/components/src/mobile/dark-mode/index.native.js index 9f36c7a28e453d..755876b4b77202 100644 --- a/packages/components/src/mobile/dark-mode/index.native.js +++ b/packages/components/src/mobile/dark-mode/index.native.js @@ -29,10 +29,16 @@ export function withTheme( WrappedComponent ) { }; } + onModeChanged( newMode ) { + this.setState( { mode: newMode } ); + } + componentDidMount() { - eventEmitter.on( 'currentModeChanged', ( newMode ) => { - this.setState( { mode: newMode } ); - } ); + this.subscription = eventEmitter.on( 'currentModeChanged', this.onModeChanged ); + } + + componentWillUnmount() { + eventEmitter.removeListener( 'currentModeChanged', this.onModeChanged ); } render() { From bce20d2dd5ea2e1e51eb90655ccbe29c7661e154 Mon Sep 17 00:00:00 2001 From: etoledom Date: Mon, 26 Aug 2019 11:17:09 +0200 Subject: [PATCH 4/5] DarkMode: Binding this.onModeChanged to `this` --- packages/components/src/mobile/dark-mode/index.native.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/components/src/mobile/dark-mode/index.native.js b/packages/components/src/mobile/dark-mode/index.native.js index 755876b4b77202..b62e23e6964e5a 100644 --- a/packages/components/src/mobile/dark-mode/index.native.js +++ b/packages/components/src/mobile/dark-mode/index.native.js @@ -24,6 +24,8 @@ export function withTheme( WrappedComponent ) { constructor( props ) { super( props ); + this.onModeChanged = this.onModeChanged.bind( this ); + this.state = { mode: initialMode, }; From da80ad8ae37a39e1d745cf5b720d2a49362ad099 Mon Sep 17 00:00:00 2001 From: etoledom Date: Mon, 26 Aug 2019 11:35:52 +0200 Subject: [PATCH 5/5] DarkMode: Adding conditional needed to pass UI Tests on CI --- packages/components/src/mobile/dark-mode/index.native.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/components/src/mobile/dark-mode/index.native.js b/packages/components/src/mobile/dark-mode/index.native.js index b62e23e6964e5a..d2b13020f027f9 100644 --- a/packages/components/src/mobile/dark-mode/index.native.js +++ b/packages/components/src/mobile/dark-mode/index.native.js @@ -40,7 +40,10 @@ export function withTheme( WrappedComponent ) { } componentWillUnmount() { - eventEmitter.removeListener( 'currentModeChanged', this.onModeChanged ); + // Conditional needed to pass UI Tests on CI + if ( eventEmitter.removeListener ) { + eventEmitter.removeListener( 'currentModeChanged', this.onModeChanged ); + } } render() {