├── .gitignore
├── .gitmodules
├── .npmignore
├── LICENSE.md
├── README.md
├── android
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── wix
│ └── RNWordpressEditor
│ ├── EditorManager.java
│ └── RNWordpressEditorPackage.java
├── example
├── .buckconfig
├── .flowconfig
├── .gitignore
├── .watchmanconfig
├── EditorScreen.js
├── WelcomeScreen.js
├── android
│ ├── app
│ │ ├── BUCK
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ ├── App.java
│ │ │ │ └── MainActivity.java
│ │ │ └── res
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── keystores
│ │ ├── BUCK
│ │ └── debug.keystore.properties
│ └── settings.gradle
├── index.android.js
├── index.ios.js
├── ios
│ ├── example.xcodeproj
│ │ ├── project.pbxproj
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── example.xcscheme
│ └── example
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.m
│ │ ├── Base.lproj
│ │ └── LaunchScreen.xib
│ │ ├── Images.xcassets
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ │ ├── Info.plist
│ │ └── main.m
└── package.json
├── index.js
├── ios
├── RNWordPressEditorManager.h
├── RNWordPressEditorManager.m
├── RNWordPressEditorViewController.h
└── RNWordPressEditorViewController.m
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | project.xcworkspace
24 |
25 | # Android/IJ
26 | #
27 | .idea
28 | .gradle
29 | local.properties
30 |
31 | # node.js
32 | #
33 | node_modules/
34 | npm-debug.log
35 |
36 | # BUCK
37 | buck-out/
38 | \.buckd/
39 | android/app/libs
40 | android/keystores/debug.keystore
41 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "ios/WordPress-Editor-iOS"]
2 | path = ios/WordPress-Editor-iOS
3 | url = https://github.com/wix/WordPress-Editor-iOS
4 | [submodule "android/WordPressAndroid"]
5 | path = android/WordPressAndroid
6 | url = git@github.com:wix/WordPress-Editor-Android.git
7 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | example
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 |
3 | Version 2, June 1991
4 |
5 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.
6 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
7 |
8 | Everyone is permitted to copy and distribute verbatim copies
9 | of this license document, but changing it is not allowed.
10 |
11 | Preamble
12 |
13 | The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
14 |
15 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
16 |
17 | To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
18 |
19 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
20 |
21 | We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
22 |
23 | Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
24 |
25 | Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
26 |
27 | The precise terms and conditions for copying, distribution and modification follow.
28 |
29 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
30 |
31 | 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
32 |
33 | Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
34 |
35 | 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
36 |
37 | You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
38 |
39 | 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
40 |
41 | a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
42 | b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
43 | c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
44 | These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
45 |
46 | Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
47 |
48 | In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
49 |
50 | 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
51 |
52 | a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
53 | b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
54 | c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
55 | The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
56 |
57 | If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
58 |
59 | 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
60 |
61 | 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
62 |
63 | 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
64 |
65 | 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
66 |
67 | If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
68 |
69 | It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
70 |
71 | This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
72 |
73 | 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
74 |
75 | 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
76 |
77 | Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
78 |
79 | 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
80 |
81 | NO WARRANTY
82 |
83 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
84 |
85 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
86 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Native WordPress Rich Text Editor
2 |
3 | React Native Wrapper for [WordPress Rich Text Editor](https://github.com/wordpress-mobile/WordPress-Editor-iOS). The WordPress-Editor is the text editor used in the official WordPress mobile [apps](https://github.com/wordpress-mobile) to create and edit pages & posts. In short it's a simple, straightforward way to visually edit HTML.
4 |
5 |
6 |
7 |
8 |
9 |
10 | ### Dependencies
11 |
12 | * [native code for the original editor](https://github.com/wordpress-mobile/WordPress-Editor-iOS) (a git submodule) - actually taken from this [leaner fork](https://github.com/wix/WordPress-Editor-iOS)
13 |
14 | * [react-native-navigation](https://github.com/wix/react-native-navigation) - native navigation library for React Native (required to natively display the editor within RN)
15 |
16 | ### How is integration possible?
17 |
18 | It isn't trivial to intergrate the WordPress editor with React Native because it is exposed in native code as a [`UIViewController`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/) and not a [`UIView`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/). React Native only has internal support for integrating native `UIViews` by [wrapping them](https://facebook.github.io/react-native/docs/native-components-ios.html) as React components.
19 |
20 | In order to integrate a `UIViewController` with RN, we have to turn to the library [react-native-navigation](https://github.com/wix/react-native-navigation) which fully supports native app skeletons with View Controllers. If you're interested in how it's achieved, take a look at the following [internal dependency](https://github.com/wix/react-native-controllers) of this awesome library.
21 |
22 | ### Installation
23 |
24 | * Make sure your project relies on React Native >= 0.25
25 |
26 | * Make sure your project uses **react-native-navigation** and that you've followed the **Installation** instructions [there](https://github.com/wix/react-native-navigation)
27 |
28 | * In your RN project root run: `npm install react-native-wordpress-editor --save`
29 |
30 | * Open your Xcode project and drag the folder `node_modules/react-native-wordpress-editor/ios` into your project
31 |
32 | ### Usage
33 |
34 | #### For a fully working example look [here](example)
35 |
36 | First, create a placeholder screen for the editor. The main purpose of this screen is to handle navigation events. See an example [here](https://github.com/wix/react-native-wordpress-editor/blob/master/example/EditorScreen.js).
37 |
38 | > Note: Make sure your screen component has been registered with `Navigation.registerComponent` like all react-native-navigation screens need to be, [example](https://github.com/wix/react-native-wordpress-editor/blob/master/example/index.ios.js).
39 |
40 | Now, to display your screen, from within one of your other app screens, push the editor:
41 |
42 | ```js
43 | this.props.navigator.push({
44 | screen: 'example.EditorScreen',
45 | title: 'Preview',
46 | passProps: {
47 | externalNativeScreenClass: 'RNWordPressEditorViewController',
48 | externalNativeScreenProps: {
49 | // the post to open in the editor, leave empty for no post
50 | post: {
51 | // title of the post
52 | title: 'Hello WorldPress',
53 | // html body of the post
54 | body: 'cool HTML body
'
55 | },
56 | // if no post shown, these placeholders will appear in the relevant fields
57 | placeHolders: {
58 | title: 'title',
59 | body: 'body'
60 | }
61 | }
62 | }
63 | });
64 | ```
65 |
66 | ### API Reference
67 |
68 | Once the editor screen is displayed, you can communicate with it using a JS interface.
69 |
70 | ```js
71 | import EditorManager from 'react-native-wordpress-editor';
72 | ```
73 |
74 | * **`EditorManager.setEditingState(editing: boolean)`**
75 | Switch between editing and preview modes (accepts a boolean).
76 |
77 | * **`EditorManager.resetStateToInitial()`**
78 | Reset to the initial state right after the screen was pushed (with original props).
79 |
80 | * **`EditorManager.isPostChanged(): Promise`**
81 | Returns a promise of a boolean (since it's async) whether the state is still the initial one.
82 |
83 | * **`EditorManager.getPostData(): Promise<{title: string, body: string}>`**
84 | Returns a promise of a simple object holding the `title` and HTML `body` of the post.
85 |
86 | * **`EditorManager.addImages(images: Array<{url: string}>)`**
87 | Adds images at the current cursor location in the editor, takes an array of simple objects with the `url` of each image.
88 |
89 | ### Credits and Attributions
90 |
91 | This project depends on:
92 |
93 | * [WordPress-Editor-iOS](https://github.com/wix/WordPress-Editor-iOS)
94 | * [WordPress-Editor-Android](https://github.com/wix/WordPress-Editor-Android)
95 |
96 | ### License
97 |
98 | See [LICENSE](LICENSE.md)
99 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the react-native-wordpress-editor project.
3 | *
4 | * Copyright (C) 2016 Wix.com Ltd
5 | *
6 | * react-native-wordpress-editor is free software: you can redistribute it
7 | * and/or modify it under the terms of the GNU General Public License as
8 | * published by the Free Software Foundation, either version 2 of the License.
9 | *
10 | * react-native-wordpress-editor is distributed in the hope that it will be
11 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 | * Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along
16 | * with react-native-wordpress-editor. If not, see
17 | */
18 |
19 | apply plugin: 'com.android.library'
20 |
21 | android {
22 | compileSdkVersion 23
23 | buildToolsVersion "23.0.3"
24 |
25 | defaultConfig {
26 | minSdkVersion 16
27 | targetSdkVersion 22
28 | versionCode 1
29 | versionName "1.0"
30 | ndk {
31 | abiFilters "armeabi-v7a", "x86"
32 | }
33 | }
34 | lintOptions {
35 | warning 'InvalidPackage'
36 | }
37 | }
38 |
39 | dependencies {
40 | compile 'com.facebook.react:react-native:0.20.+'
41 | compile project(':WordPressEditor')
42 | }
43 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
18 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/android/src/main/java/com/wix/RNWordpressEditor/EditorManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the react-native-wordpress-editor project.
3 | *
4 | * Copyright (C) 2016 Wix.com Ltd
5 | *
6 | * react-native-wordpress-editor is free software: you can redistribute it
7 | * and/or modify it under the terms of the GNU General Public License as
8 | * published by the Free Software Foundation, either version 2 of the License.
9 | *
10 | * react-native-wordpress-editor is distributed in the hope that it will be
11 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 | * Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along
16 | * with react-native-wordpress-editor. If not, see
17 | */
18 |
19 | package com.wix.RNWordpressEditor;
20 |
21 | import android.os.Bundle;
22 |
23 | import com.facebook.react.bridge.Arguments;
24 | import com.facebook.react.bridge.Promise;
25 | import com.facebook.react.bridge.ReactApplicationContext;
26 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
27 | import com.facebook.react.bridge.ReactMethod;
28 | import com.facebook.react.bridge.ReadableArray;
29 | import com.facebook.react.bridge.WritableMap;
30 | import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
31 |
32 | import org.wordpress.android.editor.EditorFragment;
33 | import org.wordpress.android.editor.EditorFragmentAbstract;
34 | import org.wordpress.android.util.helpers.MediaFile;
35 |
36 | /**
37 | * Created by yedidyak on 24/07/2016.
38 | */
39 | public class EditorManager extends ReactContextBaseJavaModule implements EditorFragmentAbstract.EditorFragmentListener {
40 |
41 | private static EditorFragment editorFragment;
42 | private static String originalTitle = "";
43 | private static String originalBody = "";
44 |
45 | private static EditorManager instance;
46 |
47 | public static EditorManager getInstance() {
48 | return instance;
49 | }
50 |
51 | public EditorManager(ReactApplicationContext reactContext) {
52 | super(reactContext);
53 | instance = this;
54 | }
55 |
56 | // @Override
57 | public String getName() {
58 | return "RNWordPressEditorManager";
59 | }
60 |
61 | @ReactMethod
62 | public void setBottomToolbarHidden(final boolean hidden, final boolean animated){
63 | //This is just here to match the iOS API, but the prduct doesn;t have a bottom toolbar
64 | }
65 |
66 | @ReactMethod
67 | public void addImages(final ReadableArray images){
68 | getReactApplicationContext().runOnUiQueueThread(new Runnable() {
69 | @Override
70 | public void run() {
71 | for(int i = 0; i < images.size(); i++) {
72 | String url = images.getMap(i).getString("url");
73 | editorFragment.appendMediaFile(url);
74 | }
75 | }
76 | });
77 | }
78 |
79 | @ReactMethod
80 | public void getPostData(final Promise promise){
81 | CharSequence title = editorFragment.getTitle();
82 | CharSequence body = editorFragment.getContent();
83 |
84 | if(title == null || body == null) {
85 | promise.reject("EDITOR", "FAILED TO GET POST DATA");
86 | return;
87 | }
88 |
89 | WritableMap post = Arguments.createMap();
90 | post.putString("title", title.toString());
91 | post.putString("body", body.toString());
92 | promise.resolve(post);
93 | }
94 |
95 | @ReactMethod
96 | public void isPostChanged(final Promise promise){
97 | getReactApplicationContext().runOnUiQueueThread(new Runnable() {
98 | @Override
99 | public void run() {
100 | String title = editorFragment.getTitle().toString();
101 | String body = editorFragment.getContent().toString();
102 | boolean changed = !title.equals(originalTitle) || !body.equals(originalBody);
103 | promise.resolve(changed);
104 | }
105 | });
106 | }
107 |
108 | @ReactMethod
109 | public void resetStateToInitial(){
110 | getReactApplicationContext().runOnUiQueueThread(new Runnable() {
111 | @Override
112 | public void run() {
113 | editorFragment.setTitle(originalTitle);
114 | editorFragment.setContent(originalBody);
115 | editorFragment.updateVisualEditorFields();
116 | }
117 | });
118 | }
119 |
120 | @ReactMethod
121 | public void showKeyboardIfEditing(){
122 | getReactApplicationContext().runOnUiQueueThread(new Runnable() {
123 | @Override
124 | public void run() {
125 | editorFragment.showKeyboardIfEditing();
126 | }
127 | });
128 | }
129 |
130 | @ReactMethod
131 | public void dismissKeyboardIfEditing(){
132 | getReactApplicationContext().runOnUiQueueThread(new Runnable() {
133 | @Override
134 | public void run() {
135 | editorFragment.dismissKeyboard();
136 | }
137 | });
138 | }
139 |
140 | @ReactMethod
141 | public void setEditingState(final boolean isEditing){
142 | validateFragment("setEditingState");
143 | getReactApplicationContext().runOnUiQueueThread(new Runnable() {
144 | @Override
145 | public void run() {
146 | editorFragment.setEditable(isEditing);
147 | }
148 | });
149 | }
150 |
151 | private void validateFragment(String method) {
152 | if(editorFragment == null) {
153 | throw new RuntimeException("Called " + method + " when there was no EditorFragment!");
154 | }
155 | }
156 |
157 | public static EditorFragment getFragment(Bundle props) {
158 |
159 | String placeholderTitle = "";
160 | String placeholderBody = "";
161 | boolean editable = false;
162 |
163 | if (props != null) {
164 | Bundle post = props.getBundle("post");
165 | if (post != null) {
166 | originalTitle = post.getString("title");
167 | originalBody = post.getString("body");
168 | editable = post.getBoolean("isNewPost");
169 | }
170 | Bundle placeHolders = props.getBundle("placeHolders");
171 | if (placeHolders != null) {
172 | placeholderTitle = placeHolders.getString("title");
173 | placeholderBody = placeHolders.getString("body");
174 | }
175 | }
176 |
177 | editorFragment = EditorFragment.newInstance(instance, originalTitle, originalBody);
178 | editorFragment.setShowHtmlButtonVisible(false);
179 | editorFragment.setEditable(editable);
180 | editorFragment.setTitlePlaceholder(placeholderTitle);
181 | editorFragment.setContentPlaceholder(placeholderBody);
182 | editorFragment.setEditorFragmentListener(instance);
183 |
184 | return editorFragment;
185 | }
186 |
187 | //Listeners
188 |
189 | @Override
190 | public void onEditorFragmentInitialized() {
191 |
192 | }
193 |
194 | @Override
195 | public void onSettingsClicked() {
196 |
197 | }
198 |
199 | @Override
200 | public void onAddMediaClicked() {
201 | getReactApplicationContext().getJSModule(RCTNativeAppEventEmitter.class).emit("EventEditorDidPressMedia", null);
202 | }
203 |
204 | @Override
205 | public void onMediaRetryClicked(String mediaId) {
206 |
207 | }
208 |
209 | @Override
210 | public void onMediaUploadCancelClicked(String mediaId, boolean delete) {
211 |
212 | }
213 |
214 | @Override
215 | public void onFeaturedImageChanged(long mediaId) {
216 |
217 | }
218 |
219 | @Override
220 | public void onVideoPressInfoRequested(String videoId) {
221 |
222 | }
223 |
224 | @Override
225 | public String onAuthHeaderRequested(String url) {
226 | return null;
227 | }
228 |
229 | @Override
230 | public void saveMediaFile(MediaFile mediaFile) {
231 |
232 | }
233 |
234 | @Override
235 | public void onTrackableEvent(EditorFragmentAbstract.TrackableEvent event) {
236 |
237 | }
238 | }
239 |
--------------------------------------------------------------------------------
/android/src/main/java/com/wix/RNWordpressEditor/RNWordpressEditorPackage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the react-native-wordpress-editor project.
3 | *
4 | * Copyright (C) 2016 Wix.com Ltd
5 | *
6 | * react-native-wordpress-editor is free software: you can redistribute it
7 | * and/or modify it under the terms of the GNU General Public License as
8 | * published by the Free Software Foundation, either version 2 of the License.
9 | *
10 | * react-native-wordpress-editor is distributed in the hope that it will be
11 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 | * Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along
16 | * with react-native-wordpress-editor. If not, see
17 | */
18 |
19 | package com.wix.RNWordpressEditor;
20 |
21 | import com.facebook.react.ReactPackage;
22 | import com.facebook.react.bridge.JavaScriptModule;
23 | import com.facebook.react.bridge.NativeModule;
24 | import com.facebook.react.bridge.ReactApplicationContext;
25 | import com.facebook.react.uimanager.ViewManager;
26 |
27 | import java.util.Collections;
28 | import java.util.List;
29 |
30 | /**
31 | * Created by yedidyak on 24/07/2016.
32 | */
33 | public class RNWordpressEditorPackage implements ReactPackage {
34 |
35 | @Override
36 | public List createNativeModules(ReactApplicationContext reactContext) {
37 | return Collections.singletonList(new EditorManager(reactContext));
38 | }
39 |
40 | @Override
41 | public List> createJSModules() {
42 | return Collections.emptyList();
43 | }
44 |
45 | @Override
46 | public List createViewManagers(ReactApplicationContext reactContext) {
47 | return Collections.emptyList();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/example/.buckconfig:
--------------------------------------------------------------------------------
1 |
2 | [android]
3 | target = Google Inc.:Google APIs:23
4 |
5 | [maven_repositories]
6 | central = https://repo1.maven.org/maven2
7 |
--------------------------------------------------------------------------------
/example/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 |
3 | # We fork some components by platform.
4 | .*/*.web.js
5 | .*/*.android.js
6 |
7 | # Some modules have their own node_modules with overlap
8 | .*/node_modules/node-haste/.*
9 |
10 | # Ugh
11 | .*/node_modules/babel.*
12 | .*/node_modules/babylon.*
13 | .*/node_modules/invariant.*
14 |
15 | # Ignore react and fbjs where there are overlaps, but don't ignore
16 | # anything that react-native relies on
17 | .*/node_modules/fbjs/lib/Map.js
18 | .*/node_modules/fbjs/lib/ErrorUtils.js
19 |
20 | # Flow has a built-in definition for the 'react' module which we prefer to use
21 | # over the currently-untyped source
22 | .*/node_modules/react/react.js
23 | .*/node_modules/react/lib/React.js
24 | .*/node_modules/react/lib/ReactDOM.js
25 |
26 | .*/__mocks__/.*
27 | .*/__tests__/.*
28 |
29 | .*/commoner/test/source/widget/share.js
30 |
31 | # Ignore commoner tests
32 | .*/node_modules/commoner/test/.*
33 |
34 | # See https://github.com/facebook/flow/issues/442
35 | .*/react-tools/node_modules/commoner/lib/reader.js
36 |
37 | # Ignore jest
38 | .*/node_modules/jest-cli/.*
39 |
40 | # Ignore Website
41 | .*/website/.*
42 |
43 | # Ignore generators
44 | .*/local-cli/generator.*
45 |
46 | # Ignore BUCK generated folders
47 | .*\.buckd/
48 |
49 | # Ignore RNPM
50 | .*/local-cli/rnpm/.*
51 |
52 | .*/node_modules/is-my-json-valid/test/.*\.json
53 | .*/node_modules/iconv-lite/encodings/tables/.*\.json
54 | .*/node_modules/y18n/test/.*\.json
55 | .*/node_modules/spdx-license-ids/spdx-license-ids.json
56 | .*/node_modules/spdx-exceptions/index.json
57 | .*/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json
58 | .*/node_modules/resolve/lib/core.json
59 | .*/node_modules/jsonparse/samplejson/.*\.json
60 | .*/node_modules/json5/test/.*\.json
61 | .*/node_modules/ua-parser-js/test/.*\.json
62 | .*/node_modules/builtin-modules/builtin-modules.json
63 | .*/node_modules/binary-extensions/binary-extensions.json
64 | .*/node_modules/url-regex/tlds.json
65 | .*/node_modules/joi/.*\.json
66 | .*/node_modules/isemail/.*\.json
67 | .*/node_modules/tr46/.*\.json
68 |
69 |
70 | [include]
71 |
72 | [libs]
73 | node_modules/react-native/Libraries/react-native/react-native-interface.js
74 | node_modules/react-native/flow
75 | flow/
76 |
77 | [options]
78 | module.system=haste
79 |
80 | esproposal.class_static_fields=enable
81 | esproposal.class_instance_fields=enable
82 |
83 | munge_underscores=true
84 |
85 | module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
86 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
87 |
88 | suppress_type=$FlowIssue
89 | suppress_type=$FlowFixMe
90 | suppress_type=$FixMe
91 |
92 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-5]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
93 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-5]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
94 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
95 |
96 | [version]
97 | ^0.25.0
98 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | project.xcworkspace
24 |
25 | # Android/IJ
26 | #
27 | .idea
28 | .gradle
29 | local.properties
30 |
31 | # node.js
32 | #
33 | node_modules/
34 | npm-debug.log
35 |
36 | # BUCK
37 | buck-out/
38 | \.buckd/
39 | android/app/libs
40 | android/keystores/debug.keystore
41 |
--------------------------------------------------------------------------------
/example/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/example/EditorScreen.js:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the react-native-wordpress-editor project.
3 | *
4 | * Copyright (C) 2016 Wix.com Ltd
5 | *
6 | * react-native-wordpress-editor is free software: you can redistribute it
7 | * and/or modify it under the terms of the GNU General Public License as
8 | * published by the Free Software Foundation, either version 2 of the License.
9 | *
10 | * react-native-wordpress-editor is distributed in the hope that it will be
11 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 | * Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along
16 | * with react-native-wordpress-editor. If not, see
17 | */
18 |
19 | import React, { Component } from 'react';
20 | import {NativeAppEventEmitter} from 'react-native';
21 | import EditorManager from 'react-native-wordpress-editor';
22 |
23 | let eventSubscribers = [];
24 |
25 | export default class EditorScreen extends Component {
26 | static navigatorButtons = {
27 | rightButtons: [
28 | {
29 | title: 'Edit',
30 | id: 'edit'
31 | }
32 | ]
33 | };
34 |
35 | constructor(props) {
36 | super(props);
37 | // if you want to listen on navigator events, set this up
38 | this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
39 |
40 | var subscription = NativeAppEventEmitter.addListener(
41 | 'EventEditorDidPressMedia', () => {
42 | console.warn('Clicked Add Media!');
43 | }
44 | );
45 | eventSubscribers.push(subscription);
46 | }
47 |
48 | componentWillUnmount() {
49 | eventSubscribers.forEach((eventListener) => eventListener.remove());
50 | }
51 |
52 | onNavigatorEvent(event) {
53 | if (event.id == 'edit') {
54 | this.setEditingState(true);
55 | } else if (event.id == 'done') {
56 | this.setEditingState(false);
57 | }
58 | }
59 |
60 | setEditingState(editing) {
61 | if (editing) {
62 | this.props.navigator.setButtons({rightButtons: [
63 | {
64 | title: 'Done',
65 | id: 'done'
66 | }
67 | ]});
68 | this.props.navigator.setTitle('Edit');
69 | } else {
70 | this.props.navigator.setButtons({rightButtons: [
71 | {
72 | title: 'Edit',
73 | id: 'edit'
74 | }
75 | ]});
76 | this.props.navigator.setTitle('Preview');
77 | }
78 | EditorManager.setEditingState(editing);
79 | }
80 |
81 | /*
82 | This screen can be empty since all the content comes form the external view controller.
83 | If necessary, navigation logic, event handling and redux logic can go here
84 | */
85 |
86 | render() {
87 | return null;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/example/WelcomeScreen.js:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the react-native-wordpress-editor project.
3 | *
4 | * Copyright (C) 2016 Wix.com Ltd
5 | *
6 | * react-native-wordpress-editor is free software: you can redistribute it
7 | * and/or modify it under the terms of the GNU General Public License as
8 | * published by the Free Software Foundation, either version 2 of the License.
9 | *
10 | * react-native-wordpress-editor is distributed in the hope that it will be
11 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 | * Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along
16 | * with react-native-wordpress-editor. If not, see
17 | */
18 |
19 | import React, { Component } from 'react';
20 | import {
21 | StyleSheet,
22 | Text,
23 | View,
24 | TouchableOpacity, Platform
25 | } from 'react-native';
26 |
27 | export default class WelcomeScreen extends Component {
28 | onPress() {
29 | if(Platform.OS === 'ios') {
30 | this.props.navigator.push({
31 | screen: 'example.EditorScreen',
32 | title: 'Preview',
33 | passProps: {
34 | externalNativeScreenClass: 'RNWordPressEditorViewController',
35 | externalNativeScreenProps: {
36 | post: {
37 | title: 'Hello WorldPress',
38 | body: 'cool HTML body