Skip to content

Commit 6556adf

Browse files
authored
Merge pull request wix-incubator#14 from philpettican/release/1.3.0
Release/1.3.0
2 parents 18bf014 + 80eefda commit 6556adf

File tree

12 files changed

+125
-10
lines changed

12 files changed

+125
-10
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ To focus or blur sections, use these methods
168168
To know when the title or content are in focus, use the following methods.
169169

170170
* `setTitleFocusHandler(callbackHandler) `
171+
* `setTitleBlurHandler(callbackHandler) `
171172
* `setContentFocusHandler(callbackHandler) `
173+
* `setContentBlurHandler(callbackHandler) `
174+
* `isTitleFocused() `
175+
* `isContentFocused() `
172176

173177
This method registers a function that will get called whenver the cursor position changes or a change is made to the styling of the editor at the cursor's position., The callback will be called with an array of `actions` that are active at the cusor position, allowing a toolbar to respond to changes.
174178

@@ -319,7 +323,9 @@ This is a set of consts of all supported actions. These will be passed in arrays
319323
setTitlePlaceholder: 'SET_TITLE_PLACEHOLDER',
320324
setContentPlaceholder: 'SET_CONTENT_PLACEHOLDER',
321325
setTitleFocusHandler: 'SET_TITLE_FOCUS_HANDLER',
326+
setTitleBlurHandler: 'SET_TITLE_BLUR_HANDLER',
322327
setContentFocusHandler: 'SET_CONTENT_FOCUS_HANDLER',
328+
setContentBlurHandler: 'SET_CONTENT_BLUR_HANDLER',
323329
prepareInsert: 'PREPARE_INSERT',
324330
restoreSelection: 'RESTORE_SELECTION',
325331
setCustomCSS: 'SET_CUSTOM_CSS',

example/App.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,19 @@ export default class RichTextExample extends Component {
4545
setFocusHandlers() {
4646
this.richtext.setTitleFocusHandler(() => {
4747
//alert('title focus');
48+
//console.log(`isTitleFocused: ${this.richtext.isTitleFocused()}`);
49+
});
50+
this.richtext.setTitleBlurHandler(() => {
51+
//alert('title blur');
52+
//console.log(`isTitleFocused: ${this.richtext.isTitleFocused()}`);
4853
});
4954
this.richtext.setContentFocusHandler(() => {
5055
//alert('content focus');
56+
//console.log(`isContentFocused: ${this.richtext.isContentFocused()}`);
57+
});
58+
this.richtext.setContentBlurHandler(() => {
59+
//alert('content blur');
60+
//console.log(`isContentFocused: ${this.richtext.isContentFocused()}`);
5161
});
5262
}
5363
}

example/android/app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ import com.android.build.OutputFile
7777

7878
project.ext.react = [
7979
entryFile: "index.js",
80-
enableHermes: false, // clean and rebuild if changing
80+
enableHermes: false, // clean and rebuild if changing,
81+
cliPath: "node_modules/@haul-bundler/cli/bin/haul.js"
8182
]
8283

8384
apply from: "../../node_modules/react-native/react.gradle"

example/babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: ['module:metro-react-native-babel-preset'],
2+
presets: ['module:@haul-bundler/babel-preset-react-native'],
33
};

example/haul.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { withPolyfills, makeConfig } from "@haul-bundler/preset-0.60";
2+
3+
export default makeConfig({
4+
bundles: {
5+
index: {
6+
entry: withPolyfills('./index'),
7+
},
8+
},
9+
});

example/ios/example.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@
371371
);
372372
runOnlyForDeploymentPostprocessing = 0;
373373
shellPath = /bin/sh;
374-
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
374+
shellScript = "# added by Haul\nexport CLI_PATH=node_modules/@haul-bundler/cli/bin/haul.js\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
375375
};
376376
2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */ = {
377377
isa = PBXShellScriptBuildPhase;
@@ -385,7 +385,7 @@
385385
);
386386
runOnlyForDeploymentPostprocessing = 0;
387387
shellPath = /bin/sh;
388-
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
388+
shellScript = "# added by Haul\nexport CLI_PATH=node_modules/@haul-bundler/cli/bin/haul.js\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
389389
};
390390
6235428805B1C264DEBB160C /* [CP] Check Pods Manifest.lock */ = {
391391
isa = PBXShellScriptBuildPhase;

example/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"ios": "react-native run-ios",
88
"start": "react-native start",
99
"test": "jest",
10-
"lint": "eslint ."
10+
"lint": "eslint .",
11+
"haul": "haul start"
1112
},
1213
"dependencies": {
1314
"react": "16.9.0",
@@ -19,6 +20,9 @@
1920
"devDependencies": {
2021
"@babel/core": "^7.7.7",
2122
"@babel/runtime": "^7.7.7",
23+
"@haul-bundler/babel-preset-react-native": "^0.16.0",
24+
"@haul-bundler/cli": "^0.21.0",
25+
"@haul-bundler/preset-0.60": "^0.18.0",
2226
"@react-native-community/eslint-config": "^0.0.5",
2327
"babel-jest": "^24.9.0",
2428
"eslint": "^6.8.0",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "git",
55
"url": "https://github.com/wix/react-native-zss-rich-text-editor.git"
66
},
7-
"version": "1.2.1",
7+
"version": "1.3.0",
88
"description": "React Native Wrapper for ZSSRichTextEditor",
99
"main": "index.js",
1010
"license": "SEE LICENSE IN LICENSE",

src/RichTextEditor.js

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export default class RichTextEditor extends Component {
5454
linkTitle: '',
5555
linkUrl: '',
5656
keyboardHeight: 0,
57+
isTitleFocused: false,
58+
isContentFocused: false,
5759
};
5860
this._selectedTextChangeListeners = [];
5961
}
@@ -198,10 +200,16 @@ export default class RichTextEditor extends Component {
198200
});
199201
break;
200202
case messages.TITLE_FOCUSED:
201-
this.titleFocusHandler && this.titleFocusHandler();
203+
this._titleFocusHandler();
204+
break;
205+
case messages.TITLE_BLURRED:
206+
this._titleBlurHandler();
202207
break;
203208
case messages.CONTENT_FOCUSED:
204-
this.contentFocusHandler && this.contentFocusHandler();
209+
this._contentFocusHandler();
210+
break;
211+
case messages.CONTENT_BLURRED:
212+
this._contentBlurHandler();
205213
break;
206214
case messages.SELECTION_CHANGE: {
207215
const items = message.data.items;
@@ -412,6 +420,16 @@ export default class RichTextEditor extends Component {
412420
});
413421
}
414422

423+
isTitleFocused() {
424+
const { isTitleFocused } = this.state;
425+
return isTitleFocused;
426+
}
427+
428+
isContentFocused() {
429+
const { isContentFocused } = this.state;
430+
return isContentFocused;
431+
}
432+
415433
focusTitle() {
416434
this._sendAction(actions.focusTitle);
417435
}
@@ -601,6 +619,10 @@ export default class RichTextEditor extends Component {
601619
}
602620

603621
init() {
622+
this._sendAction(actions.setTitleFocusHandler);
623+
this._sendAction(actions.setTitleBlurHandler);
624+
this._sendAction(actions.setContentFocusHandler);
625+
this._sendAction(actions.setContentBlurHandler);
604626
this._sendAction(actions.init);
605627
this.setPlatform();
606628
if (this.props.footerHeight) {
@@ -676,14 +698,52 @@ export default class RichTextEditor extends Component {
676698
});
677699
}
678700

701+
_titleFocusHandler() {
702+
this.setState({
703+
isTitleFocused: true,
704+
}, () => {
705+
this.titleFocusHandler && this.titleFocusHandler();
706+
});
707+
};
708+
709+
_titleBlurHandler() {
710+
this.setState({
711+
isTitleFocused: false,
712+
}, () => {
713+
this.titleBlurHandler && this.titleBlurHandler();
714+
});
715+
}
716+
717+
_contentFocusHandler() {
718+
this.setState({
719+
isContentFocused: true,
720+
}, () => {
721+
this.contentFocusHandler && this.contentFocusHandler();
722+
});
723+
}
724+
725+
_contentBlurHandler() {
726+
this.setState({
727+
isContentFocused: false,
728+
}, () => {
729+
this.contentBlurHandler && this.contentBlurHandler();
730+
});
731+
}
732+
679733
setTitleFocusHandler(callbackHandler) {
680734
this.titleFocusHandler = callbackHandler;
681-
this._sendAction(actions.setTitleFocusHandler);
735+
}
736+
737+
setTitleBlurHandler(callbackHandler) {
738+
this.titleBlurHandler = callbackHandler;
682739
}
683740

684741
setContentFocusHandler(callbackHandler) {
685742
this.contentFocusHandler = callbackHandler;
686-
this._sendAction(actions.setContentFocusHandler);
743+
}
744+
745+
setContentBlurHandler(callbackHandler) {
746+
this.contentBlurHandler = callbackHandler;
687747
}
688748

689749
addSelectedTextChangeListener(listener) {

src/WebviewMessageHandler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ export const MessageConverter = action => {
101101
return `zss_editor.setFooterHeight('${action.data}');`;
102102
case `${actions.setTitleFocusHandler}`:
103103
return `zss_editor.setTitleFocusHandler();`;
104+
case `${actions.setTitleBlurHandler}`:
105+
return `zss_editor.setTitleBlurHandler();`;
104106
case `${actions.setContentFocusHandler}`:
105107
return `zss_editor.setContentFocusHandler();`;
108+
case `${actions.setContentBlurHandler}`:
109+
return `zss_editor.setContentBlurHandler();`;
106110
case `${actions.getTitleHtml}`:
107111
return `var html = zss_editor.getTitleHTML();
108112
ReactNativeWebView.postMessage(JSON.stringify({type: '${messages.TITLE_HTML_RESPONSE}', data: html}));`;

0 commit comments

Comments
 (0)