From 423c61c1a7750515df9bcc3bb2416c2d2d96a02e Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Tue, 4 Dec 2018 10:22:54 +0100 Subject: [PATCH 1/2] Do not wire OnFocus, but use onPress instead. --- src/AztecView.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/AztecView.js b/src/AztecView.js index fa668a9..5809946 100644 --- a/src/AztecView.js +++ b/src/AztecView.js @@ -125,7 +125,8 @@ class AztecView extends React.Component { } _onPress = () => { - this.focus(); + this.focus(); // Call to move the focus in RN way (TextInputState) + this._onFocus(); // Check if there are listeners set on the focus event } render() { @@ -138,7 +139,7 @@ class AztecView extends React.Component { onHTMLContentWithCursor = { this._onHTMLContentWithCursor } onSelectionChange = { this._onSelectionChange } onEnter = { this._onEnter } - onFocus = { this._onFocus } + onFocus = { () => {} } // Do nothing here, the onPress takes care of everything onBlur = { this._onBlur } onBackspace = { this._onBackspace } /> From 605962f6089377c22610763394e8bdfb0895e25d Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Tue, 4 Dec 2018 14:00:57 +0100 Subject: [PATCH 2/2] Add a better comment explaining why onFocus is empty --- src/AztecView.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/AztecView.js b/src/AztecView.js index 5809946..111ed30 100644 --- a/src/AztecView.js +++ b/src/AztecView.js @@ -139,7 +139,10 @@ class AztecView extends React.Component { onHTMLContentWithCursor = { this._onHTMLContentWithCursor } onSelectionChange = { this._onSelectionChange } onEnter = { this._onEnter } - onFocus = { () => {} } // Do nothing here, the onPress takes care of everything + // IMPORTANT: the onFocus events are thrown away as these are handled by onPress() in the upper level. + // It's necessary to do this otherwise onFocus may be set by `{...otherProps}` and thus the onPress + onFocus + // combination generate an infinite loop as described in https://github.com/wordpress-mobile/gutenberg-mobile/issues/302 + onFocus = { () => {} } onBlur = { this._onBlur } onBackspace = { this._onBackspace } />