├── .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

' 39 | }, 40 | placeHolders: {title: 'title', body: 'body'} 41 | } 42 | } 43 | }); 44 | } else { 45 | this.props.navigator.push({ 46 | screen: 'example.EditorScreen', 47 | title: 'Preview', 48 | passProps: { 49 | post: { 50 | title: 'Hello WorldPress', 51 | body: 'cool HTML body

' 52 | }, 53 | placeHolders: {title: 'title', body: 'body'} 54 | }, 55 | fragmentCreatorClassName: 'com.wix.RNWordpressEditor.EditorManager' 56 | }); 57 | } 58 | } 59 | 60 | render() { 61 | return ( 62 | 63 | 64 | 65 | Push WordPress Editor! 66 | 67 | 68 | 69 | ); 70 | } 71 | } 72 | 73 | const styles = StyleSheet.create({ 74 | container: { 75 | flex: 1, 76 | justifyContent: 'center', 77 | alignItems: 'center', 78 | backgroundColor: '#F5FCFF', 79 | } 80 | }); -------------------------------------------------------------------------------- /example/android/app/BUCK: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | # To learn about Buck see [Docs](https://buckbuild.com/). 4 | # To run your application with Buck: 5 | # - install Buck 6 | # - `npm start` - to start the packager 7 | # - `cd android` 8 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US` 9 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 10 | # - `buck install -r android/app` - compile, install and run application 11 | # 12 | 13 | lib_deps = [] 14 | for jarfile in glob(['libs/*.jar']): 15 | name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile) 16 | lib_deps.append(':' + name) 17 | prebuilt_jar( 18 | name = name, 19 | binary_jar = jarfile, 20 | ) 21 | 22 | for aarfile in glob(['libs/*.aar']): 23 | name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile) 24 | lib_deps.append(':' + name) 25 | android_prebuilt_aar( 26 | name = name, 27 | aar = aarfile, 28 | ) 29 | 30 | android_library( 31 | name = 'all-libs', 32 | exported_deps = lib_deps 33 | ) 34 | 35 | android_library( 36 | name = 'app-code', 37 | srcs = glob([ 38 | 'src/main/java/**/*.java', 39 | ]), 40 | deps = [ 41 | ':all-libs', 42 | ':build_config', 43 | ':res', 44 | ], 45 | ) 46 | 47 | android_build_config( 48 | name = 'build_config', 49 | package = 'com.example', 50 | ) 51 | 52 | android_resource( 53 | name = 'res', 54 | res = 'src/main/res', 55 | package = 'com.example', 56 | ) 57 | 58 | android_binary( 59 | name = 'app', 60 | package_type = 'debug', 61 | manifest = 'src/main/AndroidManifest.xml', 62 | keystore = '//android/keystores:debug', 63 | deps = [ 64 | ':app-code', 65 | ], 66 | ) 67 | -------------------------------------------------------------------------------- /example/android/app/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.application" 20 | 21 | import com.android.build.OutputFile 22 | 23 | /** 24 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 25 | * and bundleReleaseJsAndAssets). 26 | * These basically call `react-native bundle` with the correct arguments during the Android build 27 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 28 | * bundle directly from the development server. Below you can see all the possible configurations 29 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 30 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 31 | * 32 | * project.ext.react = [ 33 | * // the name of the generated asset file containing your JS bundle 34 | * bundleAssetName: "index.android.bundle", 35 | * 36 | * // the entry file for bundle generation 37 | * entryFile: "index.android.js", 38 | * 39 | * // whether to bundle JS and assets in debug mode 40 | * bundleInDebug: false, 41 | * 42 | * // whether to bundle JS and assets in release mode 43 | * bundleInRelease: true, 44 | * 45 | * // whether to bundle JS and assets in another build variant (if configured). 46 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 47 | * // The configuration property can be in the following formats 48 | * // 'bundleIn${productFlavor}${buildType}' 49 | * // 'bundleIn${buildType}' 50 | * // bundleInFreeDebug: true, 51 | * // bundleInPaidRelease: true, 52 | * // bundleInBeta: true, 53 | * 54 | * // the root of your project, i.e. where "package.json" lives 55 | * root: "../../", 56 | * 57 | * // where to put the JS bundle asset in debug mode 58 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 59 | * 60 | * // where to put the JS bundle asset in release mode 61 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 62 | * 63 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 64 | * // require('./image.png')), in debug mode 65 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 66 | * 67 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 68 | * // require('./image.png')), in release mode 69 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 70 | * 71 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 72 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 73 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 74 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 75 | * // for example, you might want to remove it from here. 76 | * inputExcludes: ["android/**", "ios/**"] 77 | * ] 78 | */ 79 | 80 | apply from: "../../node_modules/react-native/react.gradle" 81 | 82 | /** 83 | * Set this to true to create two separate APKs instead of one: 84 | * - An APK that only works on ARM devices 85 | * - An APK that only works on x86 devices 86 | * The advantage is the size of the APK is reduced by about 4MB. 87 | * Upload all the APKs to the Play Store and people will download 88 | * the correct one based on the CPU architecture of their device. 89 | */ 90 | def enableSeparateBuildPerCPUArchitecture = false 91 | 92 | /** 93 | * Run Proguard to shrink the Java bytecode in release builds. 94 | */ 95 | def enableProguardInReleaseBuilds = false 96 | 97 | android { 98 | compileSdkVersion 23 99 | buildToolsVersion "23.0.1" 100 | 101 | defaultConfig { 102 | applicationId "com.example" 103 | minSdkVersion 16 104 | targetSdkVersion 22 105 | versionCode 1 106 | versionName "1.0" 107 | ndk { 108 | abiFilters "armeabi-v7a", "x86" 109 | } 110 | } 111 | splits { 112 | abi { 113 | reset() 114 | enable enableSeparateBuildPerCPUArchitecture 115 | universalApk false // If true, also generate a universal APK 116 | include "armeabi-v7a", "x86" 117 | } 118 | } 119 | buildTypes { 120 | release { 121 | minifyEnabled enableProguardInReleaseBuilds 122 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 123 | } 124 | } 125 | // applicationVariants are e.g. debug, release 126 | applicationVariants.all { variant -> 127 | variant.outputs.each { output -> 128 | // For each separate APK per architecture, set a unique version code as described here: 129 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 130 | def versionCodes = ["armeabi-v7a":1, "x86":2] 131 | def abi = output.getFilter(OutputFile.ABI) 132 | if (abi != null) { // null for the universal-debug, universal-release variants 133 | output.versionCodeOverride = 134 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 135 | } 136 | } 137 | } 138 | } 139 | 140 | dependencies { 141 | compile fileTree(dir: "libs", include: ["*.jar"]) 142 | compile "com.android.support:appcompat-v7:23.0.1" 143 | compile "com.facebook.react:react-native:+" // From node_modules 144 | compile project(":rn-wix-wordpress-editor") 145 | debugCompile project(path: ':react-native-navigation', configuration: 'libraryDebug') 146 | releaseCompile project(path: ':react-native-navigation', configuration: 'libraryRelease') 147 | } 148 | 149 | // Run this once to be able to run the application with BUCK 150 | // puts all compile dependencies into folder libs for BUCK to use 151 | task copyDownloadableDepsToLibs(type: Copy) { 152 | from configurations.compile 153 | into 'libs' 154 | } 155 | -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # This file is part of the react-native-wordpress-editor project. 2 | # 3 | # Copyright (C) 2016 Wix.com Ltd 4 | # 5 | # react-native-wordpress-editor is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License as 7 | # published by the Free Software Foundation, either version 2 of the License. 8 | # 9 | # react-native-wordpress-editor is distributed in the hope that it will be 10 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 12 | # Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License along 15 | # with react-native-wordpress-editor. If not, see 16 | 17 | # If your project uses WebView with JS, uncomment the following 18 | # and specify the fully qualified class name to the JavaScript interface 19 | # class: 20 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 21 | # public *; 22 | #} 23 | 24 | # Disabling obfuscation is useful if you collect stack traces from production crashes 25 | # (unless you are using a system that supports de-obfuscate the stack traces). 26 | -dontobfuscate 27 | 28 | # React Native 29 | 30 | # Keep our interfaces so they can be used by other ProGuard rules. 31 | # See http://sourceforge.net/p/proguard/bugs/466/ 32 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 33 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 34 | 35 | # Do not strip any method/class that is annotated with @DoNotStrip 36 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 37 | -keepclassmembers class * { 38 | @com.facebook.proguard.annotations.DoNotStrip *; 39 | } 40 | 41 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 42 | void set*(***); 43 | *** get*(); 44 | } 45 | 46 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 47 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 48 | -keepclassmembers,includedescriptorclasses class * { native ; } 49 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 50 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } 51 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } 52 | 53 | -dontwarn com.facebook.react.** 54 | 55 | # okhttp 56 | 57 | -keepattributes Signature 58 | -keepattributes *Annotation* 59 | -keep class okhttp3.** { *; } 60 | -keep interface okhttp3.** { *; } 61 | -dontwarn okhttp3.** 62 | 63 | # okio 64 | 65 | -keep class sun.misc.Unsafe { *; } 66 | -dontwarn java.nio.file.* 67 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 68 | -dontwarn okio.** 69 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 37 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/App.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.example; 20 | 21 | import android.support.annotation.NonNull; 22 | 23 | import com.facebook.react.ReactPackage; 24 | import com.reactnativenavigation.NavigationApplication; 25 | import com.wix.RNWordpressEditor.*; 26 | import com.wix.RNWordpressEditor.BuildConfig; 27 | 28 | import java.util.Arrays; 29 | import java.util.Collections; 30 | import java.util.List; 31 | 32 | /** 33 | * Created by yedidyak on 28/07/2016. 34 | */ 35 | public class App extends NavigationApplication { 36 | @Override 37 | public boolean isDebug() { 38 | return true; 39 | } 40 | 41 | @NonNull 42 | @Override 43 | public List createAdditionalReactPackages() { 44 | return Arrays.asList(new RNWordpressEditorPackage()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/MainActivity.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.example; 20 | 21 | import com.reactnativenavigation.controllers.SplashActivity; 22 | 23 | /** 24 | * Created by yedidyak on 28/07/2016. 25 | */ 26 | public class MainActivity extends SplashActivity{ 27 | } 28 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wix-incubator/react-native-wordpress-editor/5b5d4ef8d5624bce318a746b7fd8f97b6dbc65a3/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wix-incubator/react-native-wordpress-editor/5b5d4ef8d5624bce318a746b7fd8f97b6dbc65a3/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wix-incubator/react-native-wordpress-editor/5b5d4ef8d5624bce318a746b7fd8f97b6dbc65a3/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wix-incubator/react-native-wordpress-editor/5b5d4ef8d5624bce318a746b7fd8f97b6dbc65a3/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | example 21 | 22 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/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 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 20 | 21 | buildscript { 22 | repositories { 23 | jcenter() 24 | } 25 | dependencies { 26 | classpath 'com.android.tools.build:gradle:2.1.2' 27 | 28 | // NOTE: Do not place your application dependencies here; they belong 29 | // in the individual module build.gradle files 30 | } 31 | } 32 | 33 | allprojects { 34 | repositories { 35 | mavenLocal() 36 | jcenter() 37 | maven { 38 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 39 | url "$projectDir/../../node_modules/react-native/android" 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # This file is part of the react-native-wordpress-editor project. 2 | # 3 | # Copyright (C) 2016 Wix.com Ltd 4 | # 5 | # react-native-wordpress-editor is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License as 7 | # published by the Free Software Foundation, either version 2 of the License. 8 | # 9 | # react-native-wordpress-editor is distributed in the hope that it will be 10 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 12 | # Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License along 15 | # with react-native-wordpress-editor. If not, see 16 | 17 | # Project-wide Gradle settings. 18 | 19 | android.useDeprecatedNdk=true 20 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wix-incubator/react-native-wordpress-editor/5b5d4ef8d5624bce318a746b7fd8f97b6dbc65a3/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # This file is part of the react-native-wordpress-editor project. 2 | # 3 | # Copyright (C) 2016 Wix.com Ltd 4 | # 5 | # react-native-wordpress-editor is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License as 7 | # published by the Free Software Foundation, either version 2 of the License. 8 | # 9 | # react-native-wordpress-editor is distributed in the hope that it will be 10 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 12 | # Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License along 15 | # with react-native-wordpress-editor. If not, see 16 | 17 | #Sun Jul 24 12:44:44 IDT 2016 18 | distributionBase=GRADLE_USER_HOME 19 | distributionPath=wrapper/dists 20 | zipStoreBase=GRADLE_USER_HOME 21 | zipStorePath=wrapper/dists 22 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 23 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /example/android/keystores/BUCK: -------------------------------------------------------------------------------- 1 | keystore( 2 | name = 'debug', 3 | store = 'debug.keystore', 4 | properties = 'debug.keystore.properties', 5 | visibility = [ 6 | 'PUBLIC', 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /example/android/keystores/debug.keystore.properties: -------------------------------------------------------------------------------- 1 | # This file is part of the react-native-wordpress-editor project. 2 | # 3 | # Copyright (C) 2016 Wix.com Ltd 4 | # 5 | # react-native-wordpress-editor is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License as 7 | # published by the Free Software Foundation, either version 2 of the License. 8 | # 9 | # react-native-wordpress-editor is distributed in the hope that it will be 10 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 12 | # Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License along 15 | # with react-native-wordpress-editor. If not, see 16 | 17 | key.store=debug.keystore 18 | key.alias=androiddebugkey 19 | key.store.password=android 20 | key.alias.password=android 21 | -------------------------------------------------------------------------------- /example/android/settings.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 | rootProject.name = 'example' 20 | 21 | include ':app' 22 | 23 | include ':rn-wix-wordpress-editor' 24 | project(':rn-wix-wordpress-editor').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wordpress-editor/android/') 25 | 26 | include ':WordPressEditor' 27 | project(':WordPressEditor').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-wordpress-editor/android/WordPressAndroid/WordPressEditor') 28 | 29 | include ':react-native-navigation' 30 | project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app/') 31 | -------------------------------------------------------------------------------- /example/index.android.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 | AppRegistry, 22 | StyleSheet, 23 | Text, 24 | View, 25 | TouchableOpacity 26 | } from 'react-native'; 27 | import { Navigation } from 'react-native-navigation'; 28 | import EditorScreen from './EditorScreen'; 29 | import WelcomeScreen from './WelcomeScreen'; 30 | 31 | Navigation.registerComponent('example.WelcomeScreen', () => WelcomeScreen); 32 | Navigation.registerComponent('example.EditorScreen', () => EditorScreen); 33 | 34 | Navigation.startSingleScreenApp({ 35 | screen: { 36 | screen: 'example.WelcomeScreen', 37 | navigatorStyle: { 38 | navBarTextColor: '#ffffff', 39 | navBarButtonColor: '#ffffff', 40 | navBarBackgroundColor: '#00a0d2' 41 | }, 42 | title: 'Welcome' 43 | } 44 | }); 45 | -------------------------------------------------------------------------------- /example/index.ios.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 | AppRegistry, 22 | StyleSheet, 23 | Text, 24 | View, 25 | TouchableOpacity 26 | } from 'react-native'; 27 | import { Navigation } from 'react-native-navigation'; 28 | import EditorScreen from './EditorScreen'; 29 | import WelcomeScreen from './WelcomeScreen'; 30 | 31 | Navigation.registerComponent('example.WelcomeScreen', () => WelcomeScreen); 32 | Navigation.registerComponent('example.EditorScreen', () => EditorScreen); 33 | 34 | Navigation.startSingleScreenApp({ 35 | screen: { 36 | screen: 'example.WelcomeScreen', 37 | navigatorStyle: { 38 | navBarTextColor: '#ffffff', 39 | navBarButtonColor: '#ffffff', 40 | navBarBackgroundColor: '#00a0d2' 41 | }, 42 | title: 'Welcome' 43 | } 44 | }); 45 | -------------------------------------------------------------------------------- /example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /example/ios/example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (nonatomic, strong) UIWindow *window; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /example/ios/example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import "AppDelegate.h" 11 | 12 | #import "RCCManager.h" 13 | 14 | @implementation AppDelegate 15 | 16 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 17 | { 18 | NSURL *jsCodeLocation; 19 | 20 | /** 21 | * Loading JavaScript code - uncomment the one you want. 22 | * 23 | * OPTION 1 24 | * Load from development server. Start the server from the repository root: 25 | * 26 | * $ npm start 27 | * 28 | * To run on device, change `localhost` to the IP address of your computer 29 | * (you can get this by typing `ifconfig` into the terminal and selecting the 30 | * `inet` value under `en0:`) and make sure your computer and iOS device are 31 | * on the same Wi-Fi network. 32 | */ 33 | 34 | jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; 35 | 36 | /** 37 | * OPTION 2 38 | * Load from pre-bundled file on disk. The static bundle is automatically 39 | * generated by the "Bundle React Native code and images" build step when 40 | * running the project on an actual device or running the project on the 41 | * simulator in the "Release" build configuration. 42 | */ 43 | 44 | // jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 45 | 46 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 47 | self.window.backgroundColor = [UIColor whiteColor]; 48 | [[RCCManager sharedInstance] initBridgeWithBundleURL:jsCodeLocation]; 49 | return YES; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /example/ios/example/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /example/ios/example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UIViewControllerBasedStatusBarAppearance 38 | 39 | NSLocationWhenInUseUsageDescription 40 | 41 | NSAppTransportSecurity 42 | 43 | 44 | NSAllowsArbitraryLoads 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /example/ios/example/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | #import "AppDelegate.h" 13 | 14 | int main(int argc, char * argv[]) { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "name": "example", 4 | "version": "0.0.1", 5 | "private": true, 6 | "scripts": { 7 | "start": "react-native start" 8 | }, 9 | "dependencies": { 10 | "react": "^15.1.0", 11 | "react-native": "^0.27.2", 12 | "react-native-navigation": "^2.0.0-experimental", 13 | "react-native-wordpress-editor": "^2.0.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /index.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 {NativeModules} from 'react-native'; 20 | module.exports = NativeModules.RNWordPressEditorManager; 21 | -------------------------------------------------------------------------------- /ios/RNWordPressEditorManager.h: -------------------------------------------------------------------------------- 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 20 | #import "RCTBridgeModule.h" 21 | 22 | /* 23 | RNWordPressEditorManager 24 | 25 | Singleton RN native manager accessible via JavaScript and controls all communications with the native editor 26 | */ 27 | 28 | @interface RNWordPressEditorManager : NSObject 29 | @end 30 | -------------------------------------------------------------------------------- /ios/RNWordPressEditorManager.m: -------------------------------------------------------------------------------- 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 "RNWordPressEditorManager.h" 20 | #import "RNWordPressEditorViewController.h" 21 | #import "RCTEventDispatcher.h" 22 | 23 | @interface RNWordPressEditorManager() 24 | @property (nonatomic, weak) RNWordPressEditorViewController *activeBlogEditorForPhotos; 25 | @end 26 | 27 | @implementation RNWordPressEditorManager 28 | 29 | RCT_EXPORT_MODULE(RNWordPressEditorManager); 30 | 31 | @synthesize bridge = _bridge; 32 | 33 | -(instancetype)init 34 | { 35 | self = [super init]; 36 | if (self) 37 | { 38 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onEditorDidPressMedia:) name:EditorDidPressMediaNotification object:nil]; 39 | } 40 | return self; 41 | } 42 | 43 | -(void)dealloc 44 | { 45 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 46 | } 47 | 48 | - (dispatch_queue_t)methodQueue 49 | { 50 | return dispatch_get_main_queue(); 51 | } 52 | 53 | +(NSError*)createErrorWithCode:(NSInteger)code description:(NSString*)description 54 | { 55 | NSString *safeDescription = (description == nil) ? @"" : description; 56 | return [NSError errorWithDomain:@"BlogEditorManager" code:code userInfo:@{NSLocalizedDescriptionKey: safeDescription}]; 57 | } 58 | 59 | +(void)performReject:(RCTPromiseRejectBlock)reject code:(NSInteger)code description:(NSString*)description 60 | { 61 | NSError *error = [RNWordPressEditorManager createErrorWithCode:code description:description]; 62 | reject([NSString stringWithFormat: @"%lu", (long)error.code], error.localizedDescription, error); 63 | } 64 | 65 | -(void)onEditorDidPressMedia:(NSNotification*)notification 66 | { 67 | self.activeBlogEditorForPhotos = [RNWordPressEditorViewController getActiveInstance]; 68 | [self.bridge.eventDispatcher sendAppEventWithName:@"EventEditorDidPressMedia" body:@{}]; 69 | } 70 | 71 | 72 | RCT_EXPORT_METHOD(setEditingState:(BOOL)editing) 73 | { 74 | RNWordPressEditorViewController *activeEditor = [RNWordPressEditorViewController getActiveInstance]; 75 | if (activeEditor == nil) 76 | { 77 | return; 78 | } 79 | 80 | if (!editing && activeEditor.isEditing) 81 | { 82 | [activeEditor stopEditing]; 83 | } 84 | else if (editing && !activeEditor.isEditing) 85 | { 86 | [activeEditor startEditing]; 87 | } 88 | } 89 | 90 | RCT_EXPORT_METHOD(dismissKeyboardIfEditing) 91 | { 92 | RNWordPressEditorViewController *activeEditor = [RNWordPressEditorViewController getActiveInstance]; 93 | if (activeEditor == nil) 94 | { 95 | return; 96 | } 97 | 98 | [activeEditor dismissKeyboardIfEditing]; 99 | } 100 | 101 | RCT_EXPORT_METHOD(showKeyboardIfEditing) 102 | { 103 | RNWordPressEditorViewController *activeEditor = [RNWordPressEditorViewController getActiveInstance]; 104 | if (activeEditor == nil) 105 | { 106 | return; 107 | } 108 | 109 | [activeEditor showKeyboardIfEditing]; 110 | } 111 | 112 | RCT_EXPORT_METHOD(resetStateToInitial) 113 | { 114 | RNWordPressEditorViewController *activeEditor = [RNWordPressEditorViewController getActiveInstance]; 115 | if (activeEditor == nil) 116 | { 117 | return; 118 | } 119 | 120 | [activeEditor setInitialTitleAndBody]; 121 | } 122 | 123 | RCT_EXPORT_METHOD(isPostChanged:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 124 | { 125 | RNWordPressEditorViewController *activeEditor = [RNWordPressEditorViewController getActiveInstance]; 126 | if (activeEditor == nil) 127 | { 128 | [RNWordPressEditorManager performReject:reject code:1000 description:@"No Active Blog Editor"]; 129 | return; 130 | } 131 | 132 | resolve(@([activeEditor initialPostChanged])); 133 | } 134 | 135 | RCT_EXPORT_METHOD(getPostData:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 136 | { 137 | RNWordPressEditorViewController *activeEditor = [RNWordPressEditorViewController getActiveInstance]; 138 | if (activeEditor == nil) 139 | { 140 | [RNWordPressEditorManager performReject:reject code:1000 description:@"No Active Blog Editor"]; 141 | return; 142 | } 143 | 144 | NSString *title = activeEditor.titleText; 145 | NSString *body = activeEditor.bodyText; 146 | 147 | NSMutableDictionary *result = [@{@"title": title != nil ? title : @"", 148 | @"body": body != nil ? body : @""} mutableCopy]; 149 | 150 | 151 | NSDictionary *coverImageData = [activeEditor coverImageData]; 152 | if (coverImageData != nil) 153 | { 154 | result[@"coverImage"] = coverImageData; 155 | } 156 | 157 | resolve(result); 158 | } 159 | 160 | RCT_EXPORT_METHOD(addImages:(NSArray*)imageURLs) 161 | { 162 | /* 163 | IMPORTANT: 164 | If this method gets called when the modal image uploader is still showing, for some reason, the WixBlogEditorViewController will not be able to actually add and present the images (the UIWebView probably can't execute the JS) 165 | For now we'll mark the images as pending so we can add them as soon as the view appears again 166 | 167 | */ 168 | 169 | //if the static reference exists the view is shown - add the images now 170 | RNWordPressEditorViewController *activeEditor = [RNWordPressEditorViewController getActiveInstance]; 171 | if (activeEditor != nil) 172 | { 173 | [activeEditor addImages:imageURLs]; 174 | return; 175 | } 176 | 177 | if (self.activeBlogEditorForPhotos == nil) 178 | { 179 | return; 180 | } 181 | 182 | self.activeBlogEditorForPhotos.pendingImagesToAdd = imageURLs; 183 | } 184 | 185 | RCT_EXPORT_METHOD(setBottomToolbarHidden:(BOOL)hidden animated:(BOOL)animated) 186 | { 187 | RNWordPressEditorViewController *activeEditor = [RNWordPressEditorViewController getActiveInstance]; 188 | if (activeEditor == nil) 189 | { 190 | return; 191 | } 192 | 193 | [activeEditor setBottomToolbarHidden:hidden animated:animated]; 194 | } 195 | 196 | @end 197 | -------------------------------------------------------------------------------- /ios/RNWordPressEditorViewController.h: -------------------------------------------------------------------------------- 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 20 | #import "WPEditorViewController.h" 21 | #import "RCCExternalViewControllerProtocol.h" 22 | 23 | /* 24 | RNWordPressEditorViewController 25 | 26 | The editor ViewController which inherits from the WordPress one. Implements RCCExternalViewControllerProtocol so it can be pushed by react-native-controllers 27 | */ 28 | 29 | 30 | extern NSString* const EditorDidPressMediaNotification; 31 | 32 | @interface RNWordPressEditorViewController : WPEditorViewController 33 | 34 | @property (nonatomic, strong) NSArray *pendingImagesToAdd; 35 | 36 | +(RNWordPressEditorViewController*)getActiveInstance; 37 | 38 | -(void)setInitialTitleAndBody; 39 | -(BOOL)initialPostChanged; 40 | -(NSDictionary*)coverImageData; 41 | -(void)addImages:(NSArray*)images; 42 | -(void)setBottomToolbarHidden:(BOOL)hidden animated:(BOOL)animated; 43 | -(void)dismissKeyboardIfEditing; 44 | -(void)showKeyboardIfEditing; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /ios/RNWordPressEditorViewController.m: -------------------------------------------------------------------------------- 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 "RNWordPressEditorViewController.h" 20 | #import "WPEditorView.h" 21 | #import "RCTBridge.h" 22 | #import "RCTRootView.h" 23 | #import "RCCManager.h" 24 | #import "RCTHelpers.h" 25 | #import "RCTConvert.h" 26 | #import "WPEditorField.h" 27 | 28 | NSString* const EditorDidPressMediaNotification = @"EditorDidPressMedia"; 29 | 30 | @interface UILabelWithPadding : UILabel 31 | @property (nonatomic) CGFloat leftRightPadding; 32 | @end 33 | 34 | @implementation UILabelWithPadding 35 | - (void)drawTextInRect:(CGRect)rect 36 | { 37 | UIEdgeInsets insets = {0, self.leftRightPadding, 0, self.leftRightPadding}; 38 | [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)]; 39 | } 40 | @end 41 | 42 | static RNWordPressEditorViewController *gActiveBlogEditorViewController = nil; 43 | 44 | NSString *const DefaultDesktopEditOnlyText = @"Sorry! You can\'t edit this post from your mobile device as it may mess up your desktop design"; 45 | CGFloat const DefaultDesktopEditOnlyTextFontSize = 13; 46 | CGFloat const DefaultDesktopEditOnlyPadding = 10; 47 | CGFloat const DefaultDesktopEditOnlyBgOpacity = 1; 48 | NSString *const DefaultDesktopEditOnlyBlurBackground = @"none"; 49 | 50 | @interface RNWordPressEditorViewController () 51 | @property(nonatomic, strong) NSMutableDictionary *mediaAddedProgress; 52 | @property(nonatomic, strong) NSMutableArray *allMediaAdded; 53 | @property(nonatomic, strong) NSDictionary *props; 54 | @property (nonatomic, strong) NSString *initialTitleHtml; 55 | @property (nonatomic, strong) NSString *initialBodyHtml; 56 | @property (nonatomic) BOOL startEditingOnFirstAppear; 57 | @property (nonatomic) BOOL isFirstAppear; 58 | @property (nonatomic) BOOL isFirstLayout; 59 | @property (nonatomic, strong) RCTRootView *bottomToolbarRCTView; 60 | @property (nonatomic, strong) UILabelWithPadding *desktopEditOnlyLabel; 61 | @end 62 | 63 | @implementation RNWordPressEditorViewController 64 | 65 | @synthesize controllerDelegate; 66 | 67 | - (instancetype)init 68 | { 69 | self = [self initWithMode:kWPEditorViewControllerModePreview]; 70 | if (self) 71 | { 72 | self.delegate = self; 73 | 74 | self.startEditingOnFirstAppear = NO; 75 | self.isFirstAppear = YES; 76 | self.isFirstLayout = NO; 77 | self.mediaAddedProgress = [NSMutableDictionary dictionary]; 78 | self.allMediaAdded = [NSMutableArray array]; 79 | 80 | gActiveBlogEditorViewController = self; 81 | 82 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onRNReload) name:RCTReloadNotification object:nil]; 83 | } 84 | return self; 85 | } 86 | 87 | +(RNWordPressEditorViewController*)getActiveInstance 88 | { 89 | return gActiveBlogEditorViewController; 90 | } 91 | 92 | -(void)cleanup 93 | { 94 | gActiveBlogEditorViewController = nil; 95 | 96 | if (self.bottomToolbarRCTView != nil) 97 | { 98 | [self.bottomToolbarRCTView.contentView.layer removeObserver:self forKeyPath:@"frame" context:nil]; 99 | [self.bottomToolbarRCTView.contentView.layer removeObserver:self forKeyPath:@"bounds" context:NULL]; 100 | self.bottomToolbarRCTView = nil; 101 | } 102 | 103 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 104 | } 105 | 106 | -(void)dealloc 107 | { 108 | [self cleanup]; 109 | } 110 | 111 | -(void)onRNReload 112 | { 113 | [self cleanup]; 114 | } 115 | 116 | -(void)setProps:(nullable NSDictionary*)props 117 | { 118 | _props = props; 119 | 120 | self.startEditingOnFirstAppear = [props[@"startEditingOnFirstAppear"] boolValue]; 121 | self.initialTitleHtml = [props valueForKeyPath:@"post.title"]; 122 | 123 | NSString *bodyHtml = [props valueForKeyPath:@"post.body"]; 124 | if ([bodyHtml length] > 0) 125 | { 126 | //make sure image source has explicit http scheme (won't load with //) 127 | bodyHtml = [bodyHtml stringByReplacingOccurrencesOfString:@"src=\"//" withString:@"src=\"http://"]; 128 | } 129 | 130 | self.initialBodyHtml = bodyHtml; 131 | 132 | if (props[@"BottomBarComponent"] != nil) 133 | { 134 | NSString *bottomComponentName = [props valueForKeyPath:@"BottomBarComponent.name"]; 135 | if (bottomComponentName != nil) 136 | { 137 | NSDictionary *bottomComponentProps = [props valueForKeyPath:@"BottomBarComponent.props"]; 138 | self.bottomToolbarRCTView = [[RCTRootView alloc] initWithBridge:[[RCCManager sharedInstance] getBridge] moduleName:bottomComponentName initialProperties:bottomComponentProps]; 139 | self.bottomToolbarRCTView.autoresizingMask |= UIViewAutoresizingFlexibleTopMargin; 140 | self.bottomToolbarRCTView.backgroundColor = [UIColor clearColor]; 141 | self.bottomToolbarRCTView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight; 142 | [self.view addSubview:self.bottomToolbarRCTView]; 143 | 144 | [self.bottomToolbarRCTView.contentView.layer addObserver:self forKeyPath:@"frame" options:0 context:nil]; 145 | [self.bottomToolbarRCTView.contentView.layer addObserver:self forKeyPath:@"bounds" options:0 context:NULL]; 146 | } 147 | 148 | if ([[props valueForKeyPath:@"BottomBarComponent.initiallyHidden"] boolValue]) 149 | { 150 | [self setBottomToolbarHidden:YES animated:NO]; 151 | } 152 | } 153 | 154 | self.titleFocusHidesToolbar = [props[@"titleFocusHidesToolbar"] boolValue]; 155 | } 156 | 157 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 158 | { 159 | CGSize frameSize = CGSizeZero; 160 | if ([object isKindOfClass:[CALayer class]]) 161 | frameSize = ((CALayer*)object).frame.size; 162 | if ([object isKindOfClass:[UIView class]]) 163 | frameSize = ((UIView*)object).frame.size; 164 | 165 | CGSize prevFrameSize = self.bottomToolbarRCTView.frame.size; 166 | if (!CGSizeEqualToSize(frameSize, prevFrameSize)) 167 | { 168 | CGFloat yOffset = frameSize.height + [UIApplication sharedApplication].statusBarFrame.size.height; 169 | if (self.navigationController != nil) 170 | { 171 | yOffset += self.navigationController.navigationBar.frame.size.height; 172 | } 173 | 174 | self.bottomToolbarRCTView.frame = CGRectMake((self.view.frame.size.width - frameSize.width) * 0.5, self.view.frame.size.height - frameSize.height, frameSize.width, frameSize.height); 175 | self.editorView.additionalContentInset = UIEdgeInsetsMake(0, 0, frameSize.height - prevFrameSize.height, 0); 176 | } 177 | } 178 | 179 | -(WPEditorViewControllerElementTag)elementTagFromString:(NSString*)elementTypeString 180 | { 181 | if ([elementTypeString isEqualToString:@"BlockQuoteBarButton"]) 182 | return kWPEditorViewControllerElementTagBlockQuoteBarButton; 183 | 184 | if ([elementTypeString isEqualToString:@"BoldBarButton"]) 185 | return kWPEditorViewControllerElementTagBoldBarButton; 186 | 187 | if ([elementTypeString isEqualToString:@"ImageBarButton"]) 188 | return kWPEditorViewControllerElementTagInsertImageBarButton; 189 | 190 | if ([elementTypeString isEqualToString:@"InsertLinkBarButton"]) 191 | return kWPEditorViewControllerElementTagInsertLinkBarButton; 192 | 193 | if ([elementTypeString isEqualToString:@"ItalicBarButton"]) 194 | return kWPEditorViewControllerElementTagItalicBarButton; 195 | 196 | if ([elementTypeString isEqualToString:@"OrderedListBarButton"]) 197 | return kWPEditorViewControllerElementOrderedListBarButton; 198 | 199 | if ([elementTypeString isEqualToString:@"ShowSourceBarButton"]) 200 | return kWPEditorViewControllerElementShowSourceBarButton; 201 | 202 | if ([elementTypeString isEqualToString:@"iPhoneShowSourceBarButton"]) 203 | return kWPEditorViewControllerElementiPhoneShowSourceBarButton; 204 | 205 | if ([elementTypeString isEqualToString:@"StrikeThroughBarButton"]) 206 | return kWPEditorViewControllerElementStrikeThroughBarButton; 207 | 208 | if ([elementTypeString isEqualToString:@"UnorderedListBarButton"]) 209 | return kWPEditorViewControllerElementUnorderedListBarButton; 210 | 211 | return kWPEditorViewControllerElementTagUnknown; 212 | } 213 | 214 | - (void)customizeAppearance 215 | { 216 | [super customizeAppearance]; 217 | 218 | NSString *titlePlaceholder = [self.props valueForKeyPath:@"placeHolders.title"]; 219 | if (titlePlaceholder != nil) 220 | { 221 | self.titlePlaceholderText = titlePlaceholder; 222 | } 223 | 224 | NSString *bodyPlaceholder = [self.props valueForKeyPath:@"placeHolders.body"]; 225 | if (bodyPlaceholder != nil) 226 | { 227 | self.bodyPlaceholderText = bodyPlaceholder; 228 | } 229 | 230 | self.view.backgroundColor = [UIColor whiteColor]; 231 | 232 | if(self.props[@"removeToolbarButtons"]) 233 | { 234 | for (NSString *element in self.props[@"removeToolbarButtons"]) 235 | { 236 | [self.toolbarView removeToolBarItemWithTag:[self elementTagFromString:element]]; 237 | } 238 | } 239 | 240 | if(self.props[@"hideToolbarButtons"]) 241 | { 242 | for (NSString *element in self.props[@"hideToolbarButtons"]) 243 | { 244 | [self.toolbarView toolBarItemWithTag:[self elementTagFromString:element] setVisible:NO]; 245 | } 246 | } 247 | 248 | if ([self.props valueForKeyPath:@"toolbarStyle.iconTintColor"]) 249 | { 250 | [self.toolbarView setItemTintColor:[RCTConvert UIColor:[self.props valueForKeyPath:@"toolbarStyle.iconTintColor"]]]; 251 | } 252 | 253 | if ([self.props valueForKeyPath:@"toolbarStyle.disabledIconTintColor"]) 254 | { 255 | [self.toolbarView setDisabledItemTintColor:[RCTConvert UIColor:[self.props valueForKeyPath:@"toolbarStyle.disabledIconTintColor"]]]; 256 | } 257 | 258 | if ([self.props valueForKeyPath:@"toolbarStyle.selectedIconTintColor"]) 259 | { 260 | [self.toolbarView setSelectedItemTintColor:[RCTConvert UIColor:[self.props valueForKeyPath:@"toolbarStyle.selectedIconTintColor"]]]; 261 | } 262 | 263 | if ([self.props valueForKeyPath:@"toolbarStyle.topBorderColor"]) 264 | { 265 | [self.toolbarView setBorderColor:[RCTConvert UIColor:[self.props valueForKeyPath:@"toolbarStyle.topBorderColor"]]]; 266 | } 267 | 268 | if ([self.props valueForKeyPath:@"toolbarStyle.backgroundColor"]) 269 | { 270 | [self.toolbarView setBackgroundColor:[RCTConvert UIColor:[self.props valueForKeyPath:@"toolbarStyle.backgroundColor"]]]; 271 | } 272 | 273 | if ([self.props valueForKeyPath:@"placeholderColor"]) 274 | { 275 | self.placeholderColor = [RCTConvert UIColor:[self.props valueForKeyPath:@"placeholderColor"]]; 276 | } 277 | } 278 | 279 | - (void)viewWillAppear:(BOOL)animated 280 | { 281 | [super viewWillAppear:animated]; 282 | 283 | [self.controllerDelegate setStyleOnAppearForViewController:self]; 284 | } 285 | 286 | -(void)viewDidDisappear:(BOOL)animated 287 | { 288 | [super viewDidDisappear:animated]; 289 | 290 | gActiveBlogEditorViewController = nil; 291 | } 292 | 293 | -(void)viewDidLayoutSubviews 294 | { 295 | [super viewDidLayoutSubviews]; 296 | 297 | if(!self.isFirstLayout) 298 | { 299 | self.isFirstLayout = YES; 300 | 301 | [self addMobileCompatibleMessageView]; 302 | 303 | [self adjustEditorViewAdditionalInsets]; 304 | } 305 | } 306 | 307 | -(void)viewDidAppear:(BOOL)animated 308 | { 309 | [super viewDidAppear:animated]; 310 | 311 | gActiveBlogEditorViewController = self; 312 | 313 | if(self.startEditingOnFirstAppear) 314 | { 315 | self.startEditingOnFirstAppear = NO; 316 | [self startEditing]; 317 | } 318 | 319 | if (self.pendingImagesToAdd) 320 | { 321 | NSArray *imageURLs = [NSArray arrayWithArray:self.pendingImagesToAdd]; 322 | self.pendingImagesToAdd = nil; 323 | 324 | dispatch_async(dispatch_get_main_queue(), ^{ 325 | [self addImages:imageURLs]; 326 | }); 327 | } 328 | 329 | if(self.isFirstAppear) 330 | { 331 | self.isFirstAppear = NO; 332 | 333 | if (self.bottomToolbarRCTView != nil) 334 | { 335 | [RCTHelpers removeYellowBox:self.bottomToolbarRCTView]; 336 | } 337 | } 338 | } 339 | 340 | -(void)adjustEditorViewAdditionalInsets 341 | { 342 | //note: since bottomToolbarRCTView doesn't have a frame yet, it will add its own insets when it does 343 | 344 | UIEdgeInsets additionalInsets = UIEdgeInsetsZero; 345 | 346 | if (self.navigationController.navigationBar.translucent) 347 | { 348 | additionalInsets.top = 64; 349 | } 350 | 351 | if (self.desktopEditOnlyLabel != nil) 352 | { 353 | additionalInsets.top += self.desktopEditOnlyLabel.frame.size.height; 354 | } 355 | 356 | if (!UIEdgeInsetsEqualToEdgeInsets(additionalInsets, UIEdgeInsetsZero)) 357 | { 358 | self.editorView.additionalContentInset = additionalInsets; 359 | } 360 | } 361 | 362 | -(void)addMobileCompatibleMessageView 363 | { 364 | if (self.props[@"DesktopEditOnlyMessage"] != nil) 365 | { 366 | NSString *desktopEditOnlyText = [self.props valueForKeyPath:@"DesktopEditOnlyMessage.Text"]; 367 | if (desktopEditOnlyText == nil) 368 | { 369 | desktopEditOnlyText = DefaultDesktopEditOnlyText; 370 | } 371 | 372 | CGFloat desktopEditOnlyFontSize = DefaultDesktopEditOnlyTextFontSize; 373 | if ([self.props valueForKeyPath:@"DesktopEditOnlyMessage.FontSize"] != nil) 374 | { 375 | desktopEditOnlyFontSize = [[self.props valueForKeyPath:@"DesktopEditOnlyMessage.FontSize"] floatValue]; 376 | } 377 | 378 | CGFloat padding = DefaultDesktopEditOnlyPadding; 379 | if ([self.props valueForKeyPath:@"DesktopEditOnlyMessage.padding"] != nil) 380 | { 381 | padding = [[self.props valueForKeyPath:@"DesktopEditOnlyMessage.padding"] floatValue]; 382 | } 383 | 384 | CGFloat bgOpacity = DefaultDesktopEditOnlyBgOpacity; 385 | if ([self.props valueForKeyPath:@"DesktopEditOnlyMessage.backgroundOpacity"] != nil) 386 | { 387 | bgOpacity = [[self.props valueForKeyPath:@"DesktopEditOnlyMessage.backgroundOpacity"] floatValue]; 388 | } 389 | 390 | NSString *blurBackgroundStyle = [self.props valueForKeyPath:@"DesktopEditOnlyMessage.blurBackgroundStyle"]; 391 | if (blurBackgroundStyle == nil) 392 | { 393 | blurBackgroundStyle = DefaultDesktopEditOnlyBlurBackground; 394 | } 395 | 396 | self.desktopEditOnlyLabel = [[UILabelWithPadding alloc] initWithFrame:CGRectZero]; 397 | self.desktopEditOnlyLabel.leftRightPadding = padding; 398 | self.desktopEditOnlyLabel.backgroundColor = [UIColor colorWithWhite:1 alpha:bgOpacity]; 399 | self.desktopEditOnlyLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin; 400 | self.desktopEditOnlyLabel.textAlignment = NSTextAlignmentCenter; 401 | self.desktopEditOnlyLabel.font = [UIFont systemFontOfSize:desktopEditOnlyFontSize]; 402 | self.desktopEditOnlyLabel.numberOfLines = 0; 403 | self.desktopEditOnlyLabel.text = desktopEditOnlyText; 404 | 405 | 406 | CGFloat yPos = self.navigationController.navigationBar.translucent ? 64 : 0; 407 | CGSize size = [self.desktopEditOnlyLabel sizeThatFits:CGSizeMake(self.view.frame.size.width - padding * 2, CGFLOAT_MAX)]; 408 | self.desktopEditOnlyLabel.frame = CGRectMake(0, yPos, self.view.frame.size.width, size.height + padding * 2); 409 | 410 | if ([[self.props valueForKeyPath:@"DesktopEditOnlyMessage.blurBackground"] boolValue]) 411 | { 412 | UIToolbar *visualEffectView = [[UIToolbar alloc] init]; 413 | visualEffectView.backgroundColor = [UIColor clearColor]; 414 | visualEffectView.delegate = self; 415 | visualEffectView.frame = self.desktopEditOnlyLabel.frame; 416 | visualEffectView.translucent = YES; 417 | [self.view addSubview:visualEffectView]; 418 | 419 | self.desktopEditOnlyLabel.frame = CGRectMake(0, 0, self.desktopEditOnlyLabel.frame.size.width, self.desktopEditOnlyLabel.frame.size.height); 420 | [visualEffectView addSubview:self.desktopEditOnlyLabel]; 421 | } 422 | else 423 | { 424 | [self.view addSubview:self.desktopEditOnlyLabel]; 425 | } 426 | } 427 | } 428 | 429 | - (UIBarPosition)positionForBar:(id )bar 430 | { 431 | return UIBarPositionTopAttached; 432 | } 433 | 434 | -(void)addImages:(NSArray*)images 435 | { 436 | [self.allMediaAdded addObjectsFromArray:images]; 437 | 438 | for (NSDictionary *imageURLData in images) 439 | { 440 | NSString *url = imageURLData[@"url"]; 441 | __block NSString *localPlaceholderUrl = imageURLData[@"localPlaceholderUrl"]; 442 | 443 | dispatch_async(dispatch_get_main_queue(), ^ 444 | { 445 | BOOL placeholderImageExists = NO; 446 | if (localPlaceholderUrl != nil && ![[NSFileManager defaultManager] fileExistsAtPath:localPlaceholderUrl]) 447 | { 448 | NSBundle* editorBundle = [NSBundle bundleForClass:[self class]]; 449 | localPlaceholderUrl = [editorBundle pathForResource:localPlaceholderUrl ofType:@""]; 450 | if (localPlaceholderUrl != nil) 451 | { 452 | placeholderImageExists = YES; 453 | } 454 | } 455 | 456 | if (placeholderImageExists) 457 | { 458 | NSString *imageID = [[NSUUID UUID] UUIDString]; 459 | [self.editorView insertLocalImage:localPlaceholderUrl uniqueId:imageID]; 460 | [self.editorView replaceLocalImageWithRemoteImage:url uniqueId:imageID mediaId:[@(arc4random()) stringValue]]; 461 | } 462 | else 463 | { 464 | [self.editorView insertImage:url alt:@""]; 465 | } 466 | }); 467 | } 468 | } 469 | 470 | #pragma mark - WPEditorViewControllerDelegate 471 | 472 | - (void)editorDidBeginEditing:(WPEditorViewController *)editorController 473 | { 474 | } 475 | 476 | - (void)editorDidEndEditing:(WPEditorViewController *)editorController 477 | { 478 | } 479 | 480 | - (void)editorDidFinishLoadingDOM:(WPEditorViewController *)editorController 481 | { 482 | [self setInitialTitleAndBody]; 483 | } 484 | 485 | - (BOOL)editorShouldDisplaySourceView:(WPEditorViewController *)editorController 486 | { 487 | [self.editorView pauseAllVideos]; 488 | return YES; 489 | } 490 | 491 | - (void)editorDidPressMedia:(WPEditorViewController *)editorController 492 | { 493 | [[NSNotificationCenter defaultCenter] postNotificationName:EditorDidPressMediaNotification object:nil]; 494 | } 495 | 496 | - (void)editorTitleDidChange:(WPEditorViewController *)editorController 497 | { 498 | } 499 | 500 | - (void)editorTextDidChange:(WPEditorViewController *)editorController 501 | { 502 | } 503 | 504 | - (void)editorViewController:(WPEditorViewController *)editorViewController imageReplaced:(NSString *)imageId 505 | { 506 | [self.mediaAddedProgress removeObjectForKey:imageId]; 507 | } 508 | 509 | - (void)editorViewController:(WPEditorViewController *)editorViewController videoReplaced:(NSString *)videoId 510 | { 511 | [self.mediaAddedProgress removeObjectForKey:videoId]; 512 | } 513 | 514 | - (void)editorViewController:(WPEditorViewController *)editorViewController mediaRemoved:(NSString *)mediaID 515 | { 516 | NSProgress * progress = self.mediaAddedProgress[mediaID]; 517 | [progress cancel]; 518 | } 519 | 520 | -(void)setInitialTitleAndBody 521 | { 522 | [self setTitleText:self.initialTitleHtml]; 523 | [self setBodyText:self.initialBodyHtml]; 524 | } 525 | 526 | -(BOOL)initialPostChanged 527 | { 528 | NSString *initialTitleHtmlText = (self.initialTitleHtml == nil) ? @"" : self.initialTitleHtml; 529 | NSString *initialBodyHtmlText = (self.initialBodyHtml == nil) ? @"" : self.initialBodyHtml; 530 | 531 | BOOL titleChanged = ![self.titleText isEqualToString:initialTitleHtmlText]; 532 | BOOL bodyChanged = ![self.bodyText isEqualToString:initialBodyHtmlText]; 533 | return (titleChanged || bodyChanged); 534 | } 535 | 536 | -(NSDictionary*)coverImageData 537 | { 538 | NSString *mediaText = self.bodyText; 539 | 540 | NSMutableDictionary *coverImageData = nil; 541 | for (NSDictionary *imageInfo in gActiveBlogEditorViewController.allMediaAdded) 542 | { 543 | NSString *fileName = [imageInfo valueForKeyPath:@"data.file_name"]; 544 | if ([fileName length] == 0) 545 | { 546 | fileName = [imageInfo valueForKeyPath:@"data.src"]; 547 | } 548 | 549 | if ([mediaText rangeOfString:fileName].length > 0) 550 | { 551 | NSDictionary *coverImage = imageInfo[@"data"]; 552 | if (coverImage != nil) 553 | { 554 | coverImageData = [NSMutableDictionary dictionaryWithDictionary:coverImage]; 555 | if (coverImageData[@"file_name"]) coverImageData[@"src"] = coverImageData[@"file_name"]; 556 | } 557 | break; 558 | } 559 | } 560 | 561 | if (coverImageData == nil) 562 | { 563 | coverImageData = [gActiveBlogEditorViewController.props valueForKeyPath:@"post.coverImageData"]; 564 | } 565 | 566 | return coverImageData; 567 | } 568 | 569 | -(void)setBottomToolbarHidden:(BOOL)hidden animated:(BOOL)animated 570 | { 571 | if (self.bottomToolbarRCTView != nil) 572 | { 573 | CGFloat alpha = hidden ? 0 : 1; 574 | CGAffineTransform transform = hidden ? CGAffineTransformMakeTranslation(0, self.bottomToolbarRCTView.frame.size.height) : CGAffineTransformIdentity; 575 | if (animated) 576 | { 577 | [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^(){ 578 | self.bottomToolbarRCTView.alpha = alpha; 579 | self.bottomToolbarRCTView.transform = transform; 580 | } completion: nil]; 581 | } 582 | else 583 | { 584 | self.bottomToolbarRCTView.alpha = alpha; 585 | self.bottomToolbarRCTView.transform = transform; 586 | } 587 | } 588 | } 589 | 590 | -(void)dismissKeyboardIfEditing 591 | { 592 | if (self.editing && self.editorView.focusedField != nil) 593 | { 594 | [self.editorView.focusedField blur]; 595 | } 596 | } 597 | 598 | -(void)showKeyboardIfEditing 599 | { 600 | if (self.editing && self.editorView.focusedField == nil) 601 | { 602 | [self.editorView.titleField focus]; 603 | } 604 | } 605 | 606 | @end 607 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-wordpress-editor", 3 | "publishConfig": { 4 | "registry": "https://registry.npmjs.org/" 5 | }, 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/wix/react-native-wordpress-editor.git" 9 | }, 10 | "version": "2.0.1", 11 | "description": "React Native Wrapper for WordPress Rich Text Editor. The WordPress-Editor is the text editor used in the official WordPress mobile apps to create and edit pages & posts", 12 | "nativePackage": true, 13 | "bugs": { 14 | "url": "https://github.com/wix/react-native-wordpress-editor/issues" 15 | }, 16 | "homepage": "https://github.com/wix/react-native-wordpress-editor", 17 | "main": "index.js", 18 | "author": "Artal Druk ", 19 | "license": "GPL-2.0", 20 | "peerDependencies": { 21 | "react-native": ">=0.25.1", 22 | "react": ">=0.14.5" 23 | } 24 | } 25 | --------------------------------------------------------------------------------