Skip to content

Commit

Permalink
Merge pull request #24 from wordpress-mobile/fix/22-performance-issue…
Browse files Browse the repository at this point in the history
…-in-RN-lifecycle

Fix delayed update and weird output when typing fast in AztecRN
  • Loading branch information
hypest committed Jun 29, 2018
2 parents ed688d4 + a08d774 commit 873ae8f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.SimpleViewManager;
Expand Down Expand Up @@ -86,7 +88,20 @@ public Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
}

@ReactProp(name = "text")
public void setText(ReactAztecText view, String text) {
public void setText(ReactAztecText view, ReadableMap inputMap) {
if (!inputMap.hasKey("eventCount")) {
setTextfromJS(view, inputMap.getString("text"));
} else {
// Don't think there is necessity of this branch, but justin case we want to
// force a 2nd setText from JS side to Native, just set a high eventCount
int eventCount = inputMap.getInt("eventCount");
if (view.mNativeEventCount < eventCount) {
setTextfromJS(view, inputMap.getString("text"));
}
}
}

private void setTextfromJS(ReactAztecText view, String text) {
view.setIsSettingTextFromJS(true);
view.fromHtml(text);
view.setIsSettingTextFromJS(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ReactAztecText extends AztecText {

// FIXME: Used in `incrementAndGetEventCounter` but never read. I guess we can get rid of it, but before this
// check when it's used in EditText in RN. (maybe tests?)
private int mNativeEventCount = 0;
int mNativeEventCount = 0;

public ReactAztecText(ThemedReactContext reactContext) {
super(reactContext);
Expand Down
2 changes: 1 addition & 1 deletion example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class example extends React.Component {
<RCTAztecView
{...this.props}
style={[styles.aztec_editor, {minHeight: myMinHeight}]}
text = {this.state.text}
text = {{text: this.state.text}}
onContentSizeChange= {(event) => {
this.setState({height: event.nativeEvent.contentSize.height});
}}
Expand Down
2 changes: 1 addition & 1 deletion src/AztecView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {requireNativeComponent, ViewPropTypes} from 'react-native';
var aztex = {
name: 'AztecView',
propTypes: {
text: PropTypes.string,
text: PropTypes.object,
color: PropTypes.string,
maxImagesWidth: PropTypes.number,
minImagesWidth: PropTypes.number,
Expand Down

0 comments on commit 873ae8f

Please sign in to comment.