├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .flowconfig ├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── babel.config.js ├── docs ├── AtomicTypes.md ├── CustomStyles.md └── GetStarted.md ├── flow-typed └── npm │ └── stringz_vx.x.x.js ├── flow-workaround └── GeneralStub.js.flow ├── index.js ├── package-lock.json ├── package.json ├── sample ├── .buckconfig ├── .gitattributes ├── .gitignore ├── .watchmanconfig ├── __tests__ │ ├── __snapshots__ │ │ └── getBlocks.test.js.snap │ ├── components │ │ ├── BlockQuote.test.js │ │ ├── DraftJsText.test.js │ │ ├── OrderedListItem.test.js │ │ ├── TextStyled.test.js │ │ ├── UnorderedListItem.test.js │ │ ├── __snapshots__ │ │ │ ├── BlockQuote.test.js.snap │ │ │ ├── DraftJsText.test.js.snap │ │ │ ├── OrderedListItem.test.js.snap │ │ │ ├── TextStyled.test.js.snap │ │ │ └── UnorderedListItem.test.js.snap │ │ └── defaultStyles.test.js │ ├── flatAttributesList.test.js │ ├── getBlocks.test.js │ ├── helpers │ │ ├── getItemType.test.js │ │ └── isEmptyObject.test.js │ └── loadAttributes.test.js ├── android │ ├── app │ │ ├── BUCK │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── react_native_draftjs_render │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.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 ├── babel.config.js ├── index.js ├── ios │ ├── react_native_draftjs_render-tvOS │ │ └── Info.plist │ ├── react_native_draftjs_render-tvOSTests │ │ └── Info.plist │ ├── react_native_draftjs_render.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ ├── react_native_draftjs_render-tvOS.xcscheme │ │ │ └── react_native_draftjs_render.xcscheme │ ├── react_native_draftjs_render │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Base.lproj │ │ │ └── LaunchScreen.xib │ │ ├── Images.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── Info.plist │ │ └── main.m │ └── react_native_draftjs_renderTests │ │ ├── Info.plist │ │ └── react_native_draftjs_renderTests.m ├── package-lock.json ├── package.json ├── src │ ├── index.js │ └── resourceMock.json └── yarn.lock ├── src ├── components │ ├── BlockQuote.js │ ├── DraftJsText.js │ ├── OrderedListItem.js │ ├── TextStyled.js │ ├── UnorderedListItem.js │ ├── defaultStyles.js │ └── types.js ├── flatAttributesList.js ├── getBlocks.js ├── helpers │ ├── getItemType.js │ └── isEmptyObject.js ├── loadAttributes.js └── utils │ └── generateKey.js └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # Unix-style newlines with a newline ending every file 5 | [*] 6 | indent_style = space 7 | indent_size = 2 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | 16 | [Makefile] 17 | indent_style = tab 18 | indent_size = 2 19 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | android/**/*.js 2 | ios/**/*.js 3 | **/coverage/** 4 | # Ignore flowtype-test 5 | flowtype-test/index.js 6 | 7 | sample/node_modules/** 8 | sample/android/** 9 | sample/ios/** 10 | # sample/__tests__/** 11 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "parserOptions": { 4 | "ecmaFeatures": { 5 | "jsx": true, 6 | "modules": true 7 | } 8 | }, 9 | "extends": "airbnb", 10 | "rules": { 11 | "import/extensions": [2, "never", { "json": "always" }], 12 | "no-duplicate-imports": 0, 13 | "no-underscore-dangle": 0, 14 | "linebreak-style": 0, 15 | "react/forbid-prop-types": 0, 16 | "react/default-props-match-prop-types": 0, 17 | "import/no-unresolved": 0, 18 | "import/export": 2, 19 | "import/no-extraneous-dependencies": [ 20 | 2, 21 | { 22 | "devDependencies": true, 23 | } 24 | ], 25 | "import/order": [ 26 | 2, 27 | { 28 | "newlines-between": "always" 29 | } 30 | ], 31 | "import/imports-first": 2, 32 | "flowtype/define-flow-type": 1, 33 | "flowtype/use-flow-type": 1, 34 | "flowtype/require-parameter-type": 1, 35 | "flowtype/require-return-type": [ 36 | 1, 37 | "always", 38 | { 39 | "annotateUndefined": "never" 40 | } 41 | ], 42 | "flowtype/space-after-type-colon": [ 43 | 1, 44 | "always" 45 | ], 46 | "flowtype/space-before-type-colon": [ 47 | 1, 48 | "never" 49 | ], 50 | "flowtype/type-id-match": [ 51 | 1, 52 | "^([A-Z][a-z0-9]+)+Type$" 53 | ], 54 | "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], 55 | "react/sort-comp": [ 56 | 2, { 57 | "order": [ 58 | "static-methods", 59 | "/props/", 60 | "/state/", 61 | "lifecycle", 62 | "everything-else", 63 | "render" 64 | ] 65 | } 66 | ] 67 | }, 68 | "globals": { "fetch": false }, 69 | "settings": { 70 | "flowtype": { 71 | "onlyFilesWithFlowAnnotation": true 72 | }, 73 | "import/core-modules": [ 74 | "Dimensions", 75 | "ErrorUtils" 76 | ] 77 | }, 78 | "plugins": [ 79 | "react", 80 | "react-native", 81 | "flowtype" 82 | ] 83 | } 84 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | .*/node_modules/.* 3 | 4 | [options] 5 | # Workaround to deal with this issue: https://github.com/facebook/flow/issues/869 6 | # More info: https://github.com/reactjs/react-redux/issues/137#issuecomment-264199618 7 | module.name_mapper='\(react-native\)' -> '/flow-workaround/GeneralStub.js.flow' 8 | module.name_mapper='\(react-native-draftjs-render\)' -> '/flow-workaround/GeneralStub.js.flow' 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | 16 | # Directory for instrumented libs generated by jscoverage/JSCover 17 | lib-cov 18 | 19 | # Coverage directory used by tools like istanbul 20 | coverage 21 | 22 | # nyc test coverage 23 | .nyc_output 24 | 25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 26 | .grunt 27 | 28 | # node-waf configuration 29 | .lock-wscript 30 | 31 | # Compiled binary addons (http://nodejs.org/api/addons.html) 32 | build/Release 33 | 34 | # Dependency directories 35 | node_modules 36 | jspm_packages 37 | 38 | # Optional npm cache directory 39 | .npm 40 | 41 | # Optional REPL history 42 | .node_repl_history 43 | 44 | sample/react-native-draftjs-render/* 45 | 46 | # VSCode 47 | jsconfig.json 48 | 49 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | sample/ 2 | README.md 3 | Makefile 4 | .* 5 | flow-workaround 6 | flow-typed 7 | coverage 8 | docs 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "8" 4 | before_script: 5 | - "cd sample && npm install && npm run sync-lib && cd ../" 6 | script: npm run test-coveralls 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Globo Comunicação e Participações S/A 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | # Copyright (c) 2013, Payton White (https://github.com/prwhite) 4 | # 5 | # License: MIT 6 | # 7 | .SILENT: 8 | .PHONY: android ios help 9 | 10 | # See https://gist.github.com/prwhite/8168133#comment-1313022 11 | ## Help screen 12 | help: 13 | echo 14 | printf "Targets available:\n\n" 15 | awk '/^[a-zA-Z\-\_0-9]+:/ { \ 16 | helpMessage = match(lastLine, /^## (.*)/); \ 17 | if (helpMessage) { \ 18 | helpCommand = substr($$1, 0, index($$1, ":")-1); \ 19 | helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ 20 | printf "%-15s %s\n", helpCommand, helpMessage; \ 21 | } \ 22 | } \ 23 | { lastLine = $$0 }' $(MAKEFILE_LIST) 24 | echo 25 | 26 | ## Project setup 27 | setup: 28 | @npm install && cd sample && npm install && npm run sync-lib 29 | 30 | ## Setup with yarn 31 | setup-yarn: 32 | @cd sample && yarn 33 | 34 | ## Reset npm environment 35 | reset-npm: 36 | @watchman watch-del-all 37 | @cd sample && rm -rf node_modules 38 | @npm cache clean 39 | 40 | ## Clean dependencies 41 | reset: reset-npm setup 42 | 43 | ## Clean dependencies and reruns setup 44 | reset-yarn: reset-npm setup-yarn 45 | 46 | ## Run library tests 47 | test: 48 | @npm test 49 | 50 | ## Update jest snapshots 51 | test-reset: 52 | @cd sample && npm run test-reset 53 | npm test 54 | 55 | ## Run code coverage 56 | test-coverage: 57 | @npm run coverage 58 | 59 | ## Display eslint errors 60 | lint: 61 | @npm run linter 62 | 63 | ## Display flow errors 64 | flow: 65 | @npm run flow 66 | 67 | ## Stops a Flow server 68 | flow-stop: 69 | @npm run flow-stop 70 | 71 | ## Checks linter, flow types and run tests 72 | check: lint flow test 73 | 74 | ## Synchronize lib files with sample app 75 | sync-lib: 76 | @cd sample && npm run sync-lib 77 | 78 | ## Watch lib changes to update sample app 79 | watch: 80 | @cd sample && npm run watch-src 81 | 82 | ## Open iOS project on XCode 83 | open-ios: 84 | open sample/ios/react_native_draftjs_render.xcodeproj/ 85 | 86 | ## Run iOS 87 | ios: 88 | @cd sample && react-native run-ios 89 | 90 | ## Run android 91 | android: 92 | @cd sample && react-native run-android 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Native Draft.js Render 2 | 3 | [![Build Status](https://travis-ci.org/globocom/react-native-draftjs-render.svg?branch=master)](https://travis-ci.org/globocom/react-native-draftjs-render) 4 | [![Coverage Status](https://coveralls.io/repos/github/globocom/react-native-draftjs-render/badge.svg)](https://coveralls.io/github/globocom/react-native-draftjs-render) 5 | [![npm version](https://badge.fury.io/js/react-native-draftjs-render.svg)](https://www.npmjs.com/package/react-native-draftjs-render) 6 | [![license](https://img.shields.io/npm/l/react-native-draftjs-render.svg)](https://github.com/globocom/react-native-draftjs-render/blob/master/LICENSE) 7 | 8 | 9 | A React Native render for [Draft.js](http://draftjs.org/) model. 10 | 11 | ## Discussion and Support 12 | 13 | Join the [#react-native-render](https://draftjs.slack.com/messages/react_native_render) channel on DraftJS Slack team. 14 | 15 | ## Documentation 16 | 17 | * [Get Started](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/GetStarted.md) 18 | * [Add Custom Styles](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/CustomStyles.md) 19 | * [Handle Atomic Types](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/AtomicTypes.md) 20 | 21 | ## Getting Started 22 | Install **React Native Draft.js Render** on your React Native project, using NPM or Yarn: 23 | 24 | ```sh 25 | yarn add react-native-draftjs-render 26 | # or... 27 | npm i -S react-native-draftjs-render 28 | ``` 29 | 30 | ### Using 31 | Just import and insert your Draft.js model on getRNDraftJSBlocks: 32 | 33 | ```js 34 | import React from 'react'; 35 | import { 36 | ScrollView, 37 | AppRegistry, 38 | } from 'react-native'; 39 | 40 | import getRNDraftJSBlocks from 'react-native-draftjs-render'; 41 | import contentState from 'DraftJs/contentState'; 42 | 43 | const MyApp = () => { 44 | const blocks = getRNDraftJSBlocks({ contentState }); 45 | return ( 46 | {blocks} 47 | ); 48 | }; 49 | 50 | AppRegistry.registerComponent('MyApp', () => MyApp); 51 | ``` 52 | 53 | See our [`sample`](https://github.com/globocom/react-native-draftjs-render/tree/master/sample) folder for more details. 54 | 55 | ### Adding custom styles 56 | RNDraftJSRender comes with default styles, but you can use your own: 57 | 58 | ```js 59 | import React from 'react'; 60 | import { 61 | AppRegistry, 62 | ScrollView, 63 | StyleSheet, 64 | } from 'react-native'; 65 | 66 | import getRNDraftJSBlocks from 'react-native-draftjs-render'; 67 | import contentState from 'DraftJs/contentState'; 68 | 69 | const styles = StyleSheet.flatten({ 70 | paragraph: { 71 | color: 'pink', 72 | fontSize: 18, 73 | }, 74 | link: { 75 | color: 'blue', 76 | fontWeight: 'bold', 77 | }, 78 | }); 79 | 80 | const MyApp = () => { 81 | const blocks = getRNDraftJSBlocks({ contentState, customStyles: styles }); 82 | return ( 83 | {blocks} 84 | ); 85 | }; 86 | 87 | AppRegistry.registerComponent('MyApp', () => MyApp); 88 | ``` 89 | 90 | See more at **[Custom Styles](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/CustomStyles.md)** documentation. 91 | 92 | ## Contributing 93 | 94 | To develop using example react-native project: 95 | 96 | ``` 97 | git clone git@github.com:globocom/react-native-draftjs-render.git 98 | cd react-native-draftjs-render/ 99 | make setup 100 | ``` 101 | 102 | To run tests: 103 | 104 | ``` 105 | make test 106 | ``` 107 | 108 | To watch lib changes appearing on Sample App: 109 | 110 | ``` 111 | make watch 112 | ``` 113 | 114 | To run sample app in iOS: 115 | 116 | ``` 117 | make ios 118 | ``` 119 | 120 | To run sample app in Android: 121 | 122 | ``` 123 | make android 124 | ``` 125 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | const babelFunction = (api) => { 2 | const presets = [ 3 | 'module:metro-react-native-babel-preset', 4 | ]; 5 | api.cache.never(); 6 | return { 7 | presets, 8 | }; 9 | }; 10 | 11 | module.exports = babelFunction; 12 | -------------------------------------------------------------------------------- /docs/AtomicTypes.md: -------------------------------------------------------------------------------- 1 | # Atomic Types 2 | 3 | RNDraftJSRender makes it easy to handle atomic elements with a `atomicHandler` function. Take a look at this example: 4 | 5 | Let's say that we have a atomic of type `image` inside our `contentState.blocks`. 6 | 7 | ```json 8 | { 9 | "blocks": [ 10 | { 11 | "key": "3tvln", 12 | "type": "atomic", 13 | "data": { 14 | "type": "image", 15 | "uri": "https://lorempixel.com/400/200/" 16 | } 17 | } 18 | ] 19 | } 20 | ``` 21 | 22 | You can render this atomic passing a callback called `atomicHandler` to RNDraftJSRender. 23 | 24 | ```js 25 | const atomicHandler = (item: Object, entityMap: Object): ?React$Element<*> => { 26 | switch (item.data.type) { 27 | case 'image': 28 | return ( 29 | 30 | 34 | 35 | ); 36 | default: 37 | return null; 38 | } 39 | }; 40 | 41 | const props = { 42 | contentState, 43 | atomicHandler, 44 | }; 45 | 46 | const blocks = getRNDraftJSBlocks(props); 47 | ``` 48 | -------------------------------------------------------------------------------- /docs/CustomStyles.md: -------------------------------------------------------------------------------- 1 | # Custom Styles 2 | RNDraftJSRender comes with default styles, but you can use your own with the `customStyles` property: 3 | 4 | ```js 5 | import React from 'react'; 6 | import { 7 | ScrollView, 8 | AppRegistry, 9 | StyleSheet, 10 | } from 'react-native'; 11 | 12 | import getRNDraftJSBlocks from 'react-native-draftjs-render'; 13 | import contentState from 'DraftJs/contentState'; 14 | 15 | const styles = StyleSheet.flatten({ // Use .flatten over .create 16 | 'header-one': { 17 | fontSize: 20, 18 | }, 19 | paragraph: { 20 | color: 'pink', 21 | fontSize: 14, 22 | }, 23 | link: { 24 | color: 'blue', 25 | fontWeight: 'bold', 26 | }, 27 | }); 28 | 29 | const MyApp = () => { 30 | const blocks = getRNDraftJSBlocks({ contentState, customStyles: styles }); 31 | return ( 32 | {blocks} 33 | ); 34 | }; 35 | 36 | AppRegistry.registerComponent('MyApp', () => MyApp); 37 | ``` 38 | 39 | ## List of styles available 40 | 41 | ### Text styles 42 | 43 | All the elements (except `'code-block'`) can have inner styles and been customized with: 44 | 45 | - `bold` 46 | 47 | - `italic` 48 | 49 | - `link` 50 | 51 | - `underline` 52 | 53 | - `strikethrough` 54 | 55 | ### Elements 56 | 57 | Each element have your own style and helper styles to use: 58 | 59 | - `blockquote` 60 | - `blockquoteContainer` 61 | - `blockquoteIconBefore` 62 | - `blockquoteIconAfter` 63 | 64 | - `'code-block'` 65 | 66 | - `'header-one'` 67 | 68 | - `'header-two'` 69 | 70 | - `'header-three'` 71 | 72 | - `'header-four'` 73 | 74 | - `'header-five'` 75 | 76 | - `'header-six'` 77 | 78 | - `'ordered-list-item'` 79 | - `orderedListItemContainer` 80 | - `orderedListItemNumber` 81 | 82 | - `paragraph` 83 | 84 | - `'unordered-list-item'` 85 | - `unorderedListItemContainer` 86 | - `unorderedListItemBullet` 87 | 88 | - `unstyled` 89 | 90 | - `viewAfterList` (View placed after a list to handle styles at the end of each one) 91 | -------------------------------------------------------------------------------- /docs/GetStarted.md: -------------------------------------------------------------------------------- 1 | # Get Started 2 | 3 | First, install **React Native Draft.js Render** on your React Native project, using NPM or Yarn: 4 | 5 | ```sh 6 | yarn add react-native-draftjs-render 7 | # or... 8 | npm i -S react-native-draftjs-render 9 | ``` 10 | 11 | ## How to Use 12 | 13 | Just import and insert your Draft.js model on RNDraftJSRender: 14 | 15 | ```js 16 | import React from 'react'; 17 | import { 18 | ScrollView, 19 | AppRegistry, 20 | } from 'react-native'; 21 | 22 | import getRNDraftJSBlocks from 'react-native-draftjs-render'; 23 | import contentState from 'DraftJs/contentState'; 24 | 25 | const MyApp = () => { 26 | const blocks = getRNDraftJSBlocks({ contentState }); 27 | return ( 28 | {blocks} 29 | ); 30 | }; 31 | 32 | AppRegistry.registerComponent('MyApp', () => MyApp); 33 | ``` 34 | 35 | * `contentState`: the Draft.js model with `blocks` and `entityMap` nodes. 36 | ```js 37 | // Flow type for contentState 38 | type contentState: { 39 | blocks: Array, 40 | entityMap: Object, 41 | }; 42 | ``` 43 | 44 | See our [`sample`](https://github.com/globocom/react-native-draftjs-render/tree/master/sample) folder for more details. 45 | 46 | ## Props 47 | 48 | - **contentState**: the Draft.js model with `blocks` and `entityMap`. 49 | ```js 50 | // Flow type for contentState 51 | type contentState: { 52 | blocks: Array, 53 | entityMap: Object, 54 | }; 55 | ``` 56 | 57 | - **customStyles**: Object with your custom styles. ([Documentation](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/CustomStyles.md)). 58 | 59 | - **atomicHandler**: Function to handle atomic types ([Documentation](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/AtomicTypes.md)). 60 | 61 | - **navigate** (optional): Function to be called when `onPress` is fired. 62 | 63 | - **orderedListSeparator** (optional): String to be rendered after each number of the ordered lists. 64 | 65 | - **customBlockHandler** (optional): Default element to be rendered when some type is not knew. 66 | 67 | - **depthMargin** (optional): Margin left for each level of depth lists. 68 | 69 | - **textProps** (optional): Object containing all the Text props supported by React Native. (See [Text Props](https://facebook.github.io/react-native/docs/text.html#props)). 70 | 71 | ## Next 72 | 73 | 1. **[Custom Styles](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/CustomStyles.md)**. 74 | 2. **[Atomic Types](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/AtomicTypes.md)**. 75 | -------------------------------------------------------------------------------- /flow-typed/npm/stringz_vx.x.x.js: -------------------------------------------------------------------------------- 1 | // flow-typed signature: 1914436efddb1287bb0924d3e7940c58 2 | // flow-typed version: <>/stringz_v0.4.0/flow_v0.66.0 3 | 4 | /** 5 | * This is an autogenerated libdef stub for: 6 | * 7 | * 'stringz' 8 | * 9 | * Fill this stub out by replacing all the `any` types. 10 | * 11 | * Once filled out, we encourage you to share your work with the 12 | * community by sending a pull request to: 13 | * https://github.com/flowtype/flow-typed 14 | */ 15 | 16 | declare module 'stringz' { 17 | declare module.exports: any; 18 | } 19 | 20 | /** 21 | * We include stubs for each file inside this npm package in case you need to 22 | * require those files directly. Feel free to delete any files that aren't 23 | * needed. 24 | */ 25 | declare module 'stringz/coverage/lcov-report/prettify' { 26 | declare module.exports: any; 27 | } 28 | 29 | declare module 'stringz/coverage/lcov-report/sorter' { 30 | declare module.exports: any; 31 | } 32 | 33 | declare module 'stringz/dist/index' { 34 | declare module.exports: any; 35 | } 36 | 37 | declare module 'stringz/dist/length' { 38 | declare module.exports: any; 39 | } 40 | 41 | declare module 'stringz/dist/string' { 42 | declare module.exports: any; 43 | } 44 | 45 | // Filename aliases 46 | declare module 'stringz/coverage/lcov-report/prettify.js' { 47 | declare module.exports: $Exports<'stringz/coverage/lcov-report/prettify'>; 48 | } 49 | declare module 'stringz/coverage/lcov-report/sorter.js' { 50 | declare module.exports: $Exports<'stringz/coverage/lcov-report/sorter'>; 51 | } 52 | declare module 'stringz/dist/index.js' { 53 | declare module.exports: $Exports<'stringz/dist/index'>; 54 | } 55 | declare module 'stringz/dist/length.js' { 56 | declare module.exports: $Exports<'stringz/dist/length'>; 57 | } 58 | declare module 'stringz/dist/string.js' { 59 | declare module.exports: $Exports<'stringz/dist/string'>; 60 | } 61 | -------------------------------------------------------------------------------- /flow-workaround/GeneralStub.js.flow: -------------------------------------------------------------------------------- 1 | export default {}; 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | import getRNDraftJSBlocks from './src/getBlocks'; 10 | 11 | module.exports = getRNDraftJSBlocks; 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-draftjs-render", 3 | "description": "React Native render for draft.js model", 4 | "version": "2.9.0", 5 | "scripts": { 6 | "test": "npm run linter && npm run flow && npm run coverage", 7 | "test-coveralls": "npm test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", 8 | "coverage": "jest --coverage", 9 | "test-reset": "jest --updateSnapshot", 10 | "linter": "eslint .", 11 | "linter:fix": "eslint . --fix", 12 | "flow": "flow", 13 | "flow-stop": "flow stop" 14 | }, 15 | "main": "index.js", 16 | "keywords": [ 17 | "react-native", 18 | "draft-js" 19 | ], 20 | "author": "globo.com", 21 | "license": "MIT", 22 | "peerDependencies": { 23 | "react": "^16.6.3", 24 | "react-native": ">=0.57.8" 25 | }, 26 | "dependencies": { 27 | "stringz": "1.0.0" 28 | }, 29 | "devDependencies": { 30 | "@babel/core": "7.2.2", 31 | "babel-core": "7.0.0-bridge.0", 32 | "babel-eslint": "10.0.1", 33 | "babel-jest": "23.6.0", 34 | "coveralls": "3.0.2", 35 | "eslint": "5.11.1", 36 | "eslint-config-airbnb": "17.1.0", 37 | "eslint-plugin-flowtype": "3.2.0", 38 | "eslint-plugin-import": "2.14.0", 39 | "eslint-plugin-jsx-a11y": "6.1.2", 40 | "eslint-plugin-react": "7.12.2", 41 | "eslint-plugin-react-native": "3.5.0", 42 | "flow-bin": "0.89.0", 43 | "jest": "23.6.0", 44 | "metro-react-native-babel-preset": "0.51.1", 45 | "react": "16.6.3", 46 | "react-dom": "16.6.3", 47 | "react-native": "0.57.8", 48 | "react-test-renderer": "16.6.3" 49 | }, 50 | "jest": { 51 | "preset": "react-native", 52 | "modulePathIgnorePatterns": [ 53 | "/sample/node_modules/" 54 | ], 55 | "clearMocks": true, 56 | "coverageDirectory": "./coverage/", 57 | "coverageReporters": [ 58 | "lcov", 59 | "text" 60 | ], 61 | "coveragePathIgnorePatterns": [ 62 | "/node_modules/", 63 | "/sample/", 64 | "/coverage/" 65 | ], 66 | "collectCoverageFrom": [ 67 | "src/**/*.{js,jsx}" 68 | ] 69 | }, 70 | "repository": { 71 | "type": "git", 72 | "url": "git+https://github.com/globocom/react-native-draftjs-render.git" 73 | }, 74 | "bugs": { 75 | "url": "https://github.com/globocom/react-native-draftjs-render/issues" 76 | }, 77 | "homepage": "https://github.com/globocom/react-native-draftjs-render#readme" 78 | } 79 | -------------------------------------------------------------------------------- /sample/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /sample/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /sample/.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/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 50 | 51 | fastlane/report.xml 52 | fastlane/Preview.html 53 | fastlane/screenshots 54 | -------------------------------------------------------------------------------- /sample/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /sample/__tests__/__snapshots__/getBlocks.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`ViewAfterList should pass props 1`] = ` 4 | 11 | `; 12 | -------------------------------------------------------------------------------- /sample/__tests__/components/BlockQuote.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | /* eslint-env jest */ 8 | 9 | import 'react-native'; 10 | 11 | import React from 'react'; 12 | import renderer from 'react-test-renderer'; 13 | 14 | import BlockQuote from '../../../src/components/BlockQuote'; 15 | 16 | it('renders correctly with a blockquote', () => { 17 | const text = 'Hello World'; 18 | const tree = renderer.create(
).toJSON(); 25 | expect(tree).toMatchSnapshot(); 26 | }); 27 | 28 | it('renders null without a blockquote', () => { 29 | const tree = renderer.create(
).toJSON(); 30 | expect(tree).toMatchSnapshot(); 31 | }); 32 | 33 | it('extends a style with a customStyle', () => { 34 | const text = 'Hello World'; 35 | const customStyles = { 36 | blockquote: { 37 | fontSize: 18, 38 | fontWeight: 'normal', 39 | letterSpacing: -0.75, 40 | lineHeight: 32, 41 | }, 42 | }; 43 | const tree = renderer.create(
null} 51 | />).toJSON(); 52 | expect(tree).toMatchSnapshot(); 53 | }); 54 | -------------------------------------------------------------------------------- /sample/__tests__/components/DraftJsText.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | /* eslint-env jest */ 8 | 9 | import 'react-native'; 10 | 11 | import React from 'react'; 12 | import renderer from 'react-test-renderer'; 13 | 14 | import DraftJsText from '../../../src/components/DraftJsText'; 15 | 16 | it('renders correctly with a text', () => { 17 | const text = 'Hello World'; 18 | const tree = renderer.create().toJSON(); 25 | expect(tree).toMatchSnapshot(); 26 | }); 27 | 28 | it('renders null without a text', () => { 29 | const tree = renderer.create().toJSON(); 30 | expect(tree).toMatchSnapshot(); 31 | }); 32 | 33 | it('extends a style with a customStyle', () => { 34 | const text = 'Hello World'; 35 | const customStyles = { 36 | paragraph: { 37 | fontSize: 18, 38 | fontWeight: 'normal', 39 | letterSpacing: -0.75, 40 | lineHeight: 32, 41 | }, 42 | }; 43 | const tree = renderer.create( null} 51 | />).toJSON(); 52 | expect(tree).toMatchSnapshot(); 53 | }); 54 | 55 | it('extends a style with a customStyle from another type', () => { 56 | const text = 'Hello World'; 57 | const customStyles = { 58 | blockquote: { 59 | fontSize: 18, 60 | fontWeight: 'normal', 61 | letterSpacing: -0.75, 62 | lineHeight: 32, 63 | }, 64 | }; 65 | const tree = renderer.create( null} 73 | />).toJSON(); 74 | expect(tree).toMatchSnapshot(); 75 | }); 76 | 77 | it('renders text-align: left', () => { 78 | const text = 'Hello World'; 79 | const data = { textAlignment: 'left' }; 80 | const tree = renderer.create().toJSON(); 88 | expect(tree).toMatchSnapshot(); 89 | }); 90 | 91 | it('renders text-align: right', () => { 92 | const text = 'Hello World'; 93 | const data = { textAlignment: 'right' }; 94 | const tree = renderer.create().toJSON(); 102 | expect(tree).toMatchSnapshot(); 103 | }); 104 | 105 | it('renders text-align: center', () => { 106 | const text = 'Hello World'; 107 | const data = { textAlignment: 'center' }; 108 | const tree = renderer.create().toJSON(); 116 | expect(tree).toMatchSnapshot(); 117 | }); 118 | -------------------------------------------------------------------------------- /sample/__tests__/components/OrderedListItem.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | /* eslint-env jest */ 8 | 9 | import 'react-native'; 10 | 11 | import React from 'react'; 12 | import renderer from 'react-test-renderer'; 13 | 14 | import OrderedListItem from '../../../src/components/OrderedListItem'; 15 | 16 | it('renders correctly with a ordered-list-item', () => { 17 | const text = 'Hello World'; 18 | const tree = renderer.create().toJSON(); 25 | expect(tree).toMatchSnapshot(); 26 | }); 27 | 28 | it('renders correctly with a ordered-list-item when depth is undefined', () => { 29 | const text = 'Hello World'; 30 | const tree = renderer.create().toJSON(); 38 | expect(tree).toMatchSnapshot(); 39 | }); 40 | 41 | it('renders correctly with a ordered-list-item when depth 1', () => { 42 | const text = 'Hello World'; 43 | const tree = renderer.create().toJSON(); 51 | expect(tree).toMatchSnapshot(); 52 | }); 53 | 54 | it('renders correctly when customStyles is undefined', () => { 55 | const text = 'Hello World'; 56 | const tree = renderer.create().toJSON(); 64 | expect(tree).toMatchSnapshot(); 65 | }); 66 | 67 | it('renders null without a ordered-list-item', () => { 68 | const tree = renderer.create().toJSON(); 69 | expect(tree).toMatchSnapshot(); 70 | }); 71 | 72 | it('extends a style with customStyles', () => { 73 | const text = 'Hello World'; 74 | const customStyles = { 75 | 'ordered-list-item': { 76 | fontSize: 18, 77 | fontWeight: 'normal', 78 | letterSpacing: -0.75, 79 | lineHeight: 32, 80 | marginLeft: 10, 81 | }, 82 | }; 83 | 84 | const tree = renderer.create( null} 92 | />).toJSON(); 93 | expect(tree).toMatchSnapshot(); 94 | }); 95 | 96 | it('extends a style with a customStyle.orderedListItemContainer', () => { 97 | const text = 'Hello World'; 98 | const customStyles = { 99 | 'ordered-list-item': { 100 | fontSize: 18, 101 | fontWeight: 'normal', 102 | letterSpacing: -0.75, 103 | lineHeight: 32, 104 | marginLeft: 10, 105 | }, 106 | orderedListItemContainer: { 107 | flex: 2, 108 | }, 109 | }; 110 | const tree = renderer.create( null} 118 | />).toJSON(); 119 | expect(tree).toMatchSnapshot(); 120 | }); 121 | 122 | it('extends a style with a customStyle.orderedListItemNumber', () => { 123 | const text = 'Hello World'; 124 | const customStyles = { 125 | 'ordered-list-item': { 126 | fontSize: 18, 127 | fontWeight: 'normal', 128 | letterSpacing: -0.75, 129 | lineHeight: 32, 130 | marginLeft: 10, 131 | }, 132 | orderedListItemNumber: { 133 | fontSize: 14, 134 | }, 135 | }; 136 | const tree = renderer.create( null} 144 | />).toJSON(); 145 | expect(tree).toMatchSnapshot(); 146 | }); 147 | 148 | it('renders correctly when orderedListItemNumber.marginLeft is set', () => { 149 | const text = 'Hello World'; 150 | const customStyles = { 151 | 'ordered-list-item': { 152 | fontSize: 18, 153 | fontWeight: 'normal', 154 | letterSpacing: -0.75, 155 | lineHeight: 32, 156 | marginLeft: 10, 157 | }, 158 | orderedListItemNumber: { 159 | marginLeft: 14, 160 | }, 161 | }; 162 | const tree = renderer.create( null} 170 | />).toJSON(); 171 | expect(tree).toMatchSnapshot(); 172 | }); 173 | -------------------------------------------------------------------------------- /sample/__tests__/components/TextStyled.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | /* eslint-env jest */ 8 | 9 | import 'react-native'; 10 | 11 | import React from 'react'; 12 | import renderer from 'react-test-renderer'; 13 | 14 | import TextStyled from '../../../src/components/TextStyled'; 15 | 16 | it('renders correctly without onPress', () => { 17 | const tree = renderer.create().toJSON(); 20 | expect(tree).toMatchSnapshot(); 21 | }); 22 | 23 | it('renders correctly with onPress', () => { 24 | const tree = renderer.create( null} 27 | />).toJSON(); 28 | expect(tree).toMatchSnapshot(); 29 | }); 30 | 31 | it('renders correctly with customStyles and multiple types', () => { 32 | const customStyles = { 33 | bold: { 34 | fontWeight: 'bold', 35 | }, 36 | italic: { 37 | fontStyle: 'italic', 38 | }, 39 | link: { 40 | textDecorationLine: 'underline', 41 | }, 42 | underline: { 43 | textDecorationLine: 'underline', 44 | }, 45 | strikethrough: { 46 | textDecorationLine: 'line-through', 47 | }, 48 | }; 49 | const typeArray = ['bold', 'italic']; 50 | const tree = renderer.create().toJSON(); 54 | expect(tree).toMatchSnapshot(); 55 | }); 56 | 57 | it('renders correctly with customStyles and single type', () => { 58 | const customStyles = { 59 | bold: { 60 | fontWeight: 'bold', 61 | }, 62 | }; 63 | const type = 'bold'; 64 | const tree = renderer.create().toJSON(); 68 | expect(tree).toMatchSnapshot(); 69 | }); 70 | -------------------------------------------------------------------------------- /sample/__tests__/components/UnorderedListItem.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | /* eslint-env jest */ 8 | 9 | import 'react-native'; 10 | 11 | import React from 'react'; 12 | import renderer from 'react-test-renderer'; 13 | 14 | import UnorderedListItem from '../../../src/components/UnorderedListItem'; 15 | 16 | it('renders correctly with a unordered-list-item', () => { 17 | const text = 'Hello World'; 18 | const tree = renderer.create().toJSON(); 25 | expect(tree).toMatchSnapshot(); 26 | }); 27 | 28 | it('renders correctly with a unordered-list-item when depth is undefined', () => { 29 | const text = 'Hello World'; 30 | const tree = renderer.create().toJSON(); 38 | expect(tree).toMatchSnapshot(); 39 | }); 40 | 41 | it('renders correctly with a unordered-list-item when depth 1', () => { 42 | const text = 'Hello World'; 43 | const tree = renderer.create().toJSON(); 51 | expect(tree).toMatchSnapshot(); 52 | }); 53 | 54 | it('renders null without a unordered-list-item', () => { 55 | const tree = renderer.create().toJSON(); 56 | expect(tree).toMatchSnapshot(); 57 | }); 58 | it('extends a style with customStyles', () => { 59 | const text = 'Hello World'; 60 | const customStyles = { 61 | 'unordered-list-item': { 62 | fontSize: 18, 63 | fontWeight: 'normal', 64 | letterSpacing: -0.75, 65 | lineHeight: 32, 66 | marginLeft: 10, 67 | }, 68 | }; 69 | 70 | const tree = renderer.create( null} 78 | />).toJSON(); 79 | expect(tree).toMatchSnapshot(); 80 | }); 81 | 82 | it('extends a style with a customStyle.unorderedListItemContainer', () => { 83 | const text = 'Hello World'; 84 | const customStyles = { 85 | 'unordered-list-item': { 86 | fontSize: 18, 87 | fontWeight: 'normal', 88 | letterSpacing: -0.75, 89 | lineHeight: 32, 90 | marginLeft: 10, 91 | }, 92 | unorderedListItemContainer: { 93 | flex: 2, 94 | }, 95 | }; 96 | const tree = renderer.create( null} 104 | />).toJSON(); 105 | expect(tree).toMatchSnapshot(); 106 | }); 107 | 108 | it('renders correctly when unorderedListItemBullet.marginLeft is set', () => { 109 | const text = 'Hello World'; 110 | const customStyles = { 111 | 'unordered-list-item': { 112 | fontSize: 18, 113 | fontWeight: 'normal', 114 | letterSpacing: -0.75, 115 | lineHeight: 32, 116 | marginLeft: 10, 117 | }, 118 | unorderedListItemBullet: { 119 | marginLeft: 14, 120 | }, 121 | }; 122 | const tree = renderer.create( null} 130 | />).toJSON(); 131 | expect(tree).toMatchSnapshot(); 132 | }); 133 | -------------------------------------------------------------------------------- /sample/__tests__/components/__snapshots__/BlockQuote.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`extends a style with a customStyle 1`] = ` 4 | 19 | 20 | 41 | Hello World 42 | 43 | 44 | 45 | `; 46 | 47 | exports[`renders correctly with a blockquote 1`] = ` 48 | 63 | 64 | 80 | Hello World 81 | 82 | 83 | 84 | `; 85 | 86 | exports[`renders null without a blockquote 1`] = ` 87 | 102 | 103 | 104 | 105 | `; 106 | -------------------------------------------------------------------------------- /sample/__tests__/components/__snapshots__/DraftJsText.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`extends a style with a customStyle 1`] = ` 4 | 23 | Hello World 24 | 25 | `; 26 | 27 | exports[`extends a style with a customStyle from another type 1`] = ` 28 | 42 | Hello World 43 | 44 | `; 45 | 46 | exports[`renders correctly with a text 1`] = ` 47 | 61 | Hello World 62 | 63 | `; 64 | 65 | exports[`renders null without a text 1`] = `null`; 66 | 67 | exports[`renders text-align: center 1`] = ` 68 | 82 | Hello World 83 | 84 | `; 85 | 86 | exports[`renders text-align: left 1`] = ` 87 | 101 | Hello World 102 | 103 | `; 104 | 105 | exports[`renders text-align: right 1`] = ` 106 | 120 | Hello World 121 | 122 | `; 123 | -------------------------------------------------------------------------------- /sample/__tests__/components/__snapshots__/OrderedListItem.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`extends a style with a customStyle.orderedListItemContainer 1`] = ` 4 | 18 | 33 | 1 34 | . 35 | 36 | 56 | Hello World 57 | 58 | 59 | `; 60 | 61 | exports[`extends a style with a customStyle.orderedListItemNumber 1`] = ` 62 | 74 | 91 | 1 92 | . 93 | 94 | 114 | Hello World 115 | 116 | 117 | `; 118 | 119 | exports[`extends a style with customStyles 1`] = ` 120 | 132 | 147 | 1 148 | . 149 | 150 | 170 | Hello World 171 | 172 | 173 | `; 174 | 175 | exports[`renders correctly when customStyles is undefined 1`] = ` 176 | 188 | 203 | 1 204 | . 205 | 206 | 220 | Hello World 221 | 222 | 223 | `; 224 | 225 | exports[`renders correctly when orderedListItemNumber.marginLeft is set 1`] = ` 226 | 238 | 255 | 1 256 | . 257 | 258 | 278 | Hello World 279 | 280 | 281 | `; 282 | 283 | exports[`renders correctly with a ordered-list-item 1`] = ` 284 | 296 | 311 | 1 312 | . 313 | 314 | 328 | Hello World 329 | 330 | 331 | `; 332 | 333 | exports[`renders correctly with a ordered-list-item when depth 1 1`] = ` 334 | 346 | 361 | 1 362 | . 363 | 364 | 378 | Hello World 379 | 380 | 381 | `; 382 | 383 | exports[`renders correctly with a ordered-list-item when depth is undefined 1`] = ` 384 | 396 | 411 | 1 412 | . 413 | 414 | 428 | Hello World 429 | 430 | 431 | `; 432 | 433 | exports[`renders null without a ordered-list-item 1`] = ` 434 | 446 | 461 | 1 462 | . 463 | 464 | 465 | `; 466 | -------------------------------------------------------------------------------- /sample/__tests__/components/__snapshots__/TextStyled.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`renders correctly with customStyles and multiple types 1`] = ` 4 | 21 | 22 | 23 | `; 24 | 25 | exports[`renders correctly with customStyles and single type 1`] = ` 26 | 41 | 42 | 43 | `; 44 | 45 | exports[`renders correctly with onPress 1`] = ` 46 | 57 | 58 | 59 | `; 60 | 61 | exports[`renders correctly without onPress 1`] = ` 62 | 72 | 73 | 74 | `; 75 | -------------------------------------------------------------------------------- /sample/__tests__/components/__snapshots__/UnorderedListItem.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`extends a style with a customStyle.unorderedListItemContainer 1`] = ` 4 | 18 | 36 | 50 | Hello World 51 | 52 | 53 | `; 54 | 55 | exports[`extends a style with customStyles 1`] = ` 56 | 68 | 86 | 106 | Hello World 107 | 108 | 109 | `; 110 | 111 | exports[`renders correctly when unorderedListItemBullet.marginLeft is set 1`] = ` 112 | 124 | 144 | 164 | Hello World 165 | 166 | 167 | `; 168 | 169 | exports[`renders correctly with a unordered-list-item 1`] = ` 170 | 182 | 200 | 214 | Hello World 215 | 216 | 217 | `; 218 | 219 | exports[`renders correctly with a unordered-list-item when depth 1 1`] = ` 220 | 232 | 250 | 264 | Hello World 265 | 266 | 267 | `; 268 | 269 | exports[`renders correctly with a unordered-list-item when depth is undefined 1`] = ` 270 | 282 | 300 | 314 | Hello World 315 | 316 | 317 | `; 318 | 319 | exports[`renders null without a unordered-list-item 1`] = ` 320 | 332 | 350 | 351 | `; 352 | -------------------------------------------------------------------------------- /sample/__tests__/components/defaultStyles.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | /* eslint-env jest */ 8 | import { defaultStylesForTest } from '../../../src/components/defaultStyles'; 9 | 10 | describe('defaultStyles', () => { 11 | describe('returns the style for each platform', () => { 12 | it('android', () => { 13 | expect(defaultStylesForTest('android')['code-block'].fontFamily).toBe('monospace'); 14 | }); 15 | 16 | it('ios', () => { 17 | expect(defaultStylesForTest('ios')['code-block'].fontFamily).toBe('Courier New'); 18 | }); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /sample/__tests__/flatAttributesList.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | /* eslint-env jest */ 8 | 9 | import flatAttributesList from '../../src/flatAttributesList'; 10 | 11 | describe('only inlineStyleRanges', () => { 12 | it('one style doesnt change anything', () => { 13 | const mock = [{ 14 | style: 'BOLD', 15 | offset: 0, 16 | length: 15, 17 | }]; 18 | const result = flatAttributesList(mock); 19 | expect(result).toEqual(mock); 20 | }); 21 | 22 | it('two styles in the same range become one item with an array of styles', () => { 23 | const mock = [{ 24 | style: 'BOLD', 25 | offset: 0, 26 | length: 15, 27 | }, 28 | { 29 | style: 'ITALIC', 30 | offset: 0, 31 | length: 15, 32 | }, 33 | { 34 | style: 'UNDERLINE', 35 | offset: 12, 36 | length: 24, 37 | }]; 38 | const result = flatAttributesList(mock); 39 | const expected = [{ 40 | style: ['BOLD', 'ITALIC'], 41 | offset: 0, 42 | length: 12, 43 | }, 44 | { 45 | style: ['BOLD', 'ITALIC', 'UNDERLINE'], 46 | offset: 12, 47 | length: 3, 48 | }, 49 | { 50 | style: 'UNDERLINE', 51 | offset: 15, 52 | length: 21, 53 | }]; 54 | expect(result).toEqual(expected); 55 | }); 56 | }); 57 | 58 | describe('only entityRanges', () => { 59 | it('with one link renders correctly', () => { 60 | const mock = [{ 61 | key: 0, 62 | offset: 0, 63 | length: 15, 64 | }]; 65 | const expected = [{ 66 | key: 0, 67 | offset: 0, 68 | length: 15, 69 | style: 'link', 70 | }]; 71 | const result = flatAttributesList(mock); 72 | expect(result).toEqual(expected); 73 | }); 74 | it('links doesnt change offset but receive link style', () => { 75 | const mock = [{ 76 | key: 0, 77 | offset: 0, 78 | length: 15, 79 | }, 80 | { 81 | key: 1, 82 | offset: 56, 83 | length: 60, 84 | }]; 85 | const expected = [{ 86 | key: 0, 87 | offset: 0, 88 | length: 15, 89 | style: 'link', 90 | }, 91 | { 92 | key: 1, 93 | offset: 56, 94 | length: 60, 95 | style: 'link', 96 | }]; 97 | const result = flatAttributesList(mock); 98 | expect(result).toEqual(expected); 99 | }); 100 | }); 101 | 102 | describe('with inlineStyleRanges and entityRanges', () => { 103 | it('a style and a link in the same range merge into one object', () => { 104 | const mock = [{ 105 | style: 'ITALIC', 106 | offset: 0, 107 | length: 15, 108 | }, 109 | { 110 | key: 0, 111 | offset: 0, 112 | length: 15, 113 | }]; 114 | const result = flatAttributesList(mock); 115 | const expected = [{ 116 | key: 0, 117 | style: ['ITALIC', 'link'], 118 | offset: 0, 119 | length: 15, 120 | }]; 121 | expect(result).toEqual(expected); 122 | }); 123 | 124 | it('two styles and a link in the same range merge into one object', () => { 125 | const mock = [{ 126 | style: 'ITALIC', 127 | offset: 0, 128 | length: 15, 129 | }, 130 | { 131 | style: 'STRIKETHROUGH', 132 | offset: 0, 133 | length: 15, 134 | }, 135 | { 136 | key: 0, 137 | offset: 0, 138 | length: 15, 139 | }]; 140 | const result = flatAttributesList(mock); 141 | const expected = [{ 142 | key: 0, 143 | style: ['ITALIC', 'STRIKETHROUGH', 'link'], 144 | offset: 0, 145 | length: 15, 146 | }]; 147 | expect(result).toEqual(expected); 148 | }); 149 | }); 150 | -------------------------------------------------------------------------------- /sample/__tests__/getBlocks.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | /* eslint-env jest */ 8 | 9 | import React from 'react'; 10 | import renderer from 'react-test-renderer'; 11 | 12 | import getBlocks, { ViewAfterList } from '../../src/getBlocks'; 13 | 14 | jest.mock('../../src/components/DraftJsText', () => 'DraftJsText'); 15 | jest.mock('../../src/components/BlockQuote', () => 'BlockQuote'); 16 | jest.mock('../../src/components/UnorderedListItem', () => 'UnorderedListItem'); 17 | jest.mock('../../src/components/OrderedListItem', () => 'OrderedListItem'); 18 | 19 | describe('return specific component based on type', () => { 20 | it('DraftJsText when type unstyled', () => { 21 | const bodyData = { blocks: [{ type: 'unstyled' }] }; 22 | const result = getBlocks({ contentState: bodyData }); 23 | expect(result[0].props.children[1].type).toBe('DraftJsText'); 24 | }); 25 | 26 | it('BlockQuote when type blockquote', () => { 27 | const bodyData = { blocks: [{ type: 'blockquote', text: 'My text' }] }; 28 | const result = getBlocks({ contentState: bodyData }); 29 | expect(result[0].props.children[1].type).toBe('BlockQuote'); 30 | }); 31 | 32 | it('UnorderedListItem when type unordered-list-item', () => { 33 | const bodyData = { blocks: [{ type: 'unordered-list-item' }] }; 34 | const result = getBlocks({ contentState: bodyData }); 35 | expect(result[0].props.children[1].type).toBe('UnorderedListItem'); 36 | }); 37 | 38 | it('OrderedListItem when type ordered-list-item', () => { 39 | const bodyData = { blocks: [{ type: 'ordered-list-item' }] }; 40 | const result = getBlocks({ contentState: bodyData }); 41 | expect(result[0].props.children[1].type).toBe('OrderedListItem'); 42 | }); 43 | 44 | it('OrderedListItem when depth is undefined', () => { 45 | const bodyData = { blocks: [{ type: 'ordered-list-item' }] }; 46 | const result = getBlocks({ contentState: bodyData }); 47 | expect(result[0].props.children[1].props.counter).toBe(1); 48 | }); 49 | 50 | it('OrderedListItem when depth is one', () => { 51 | const bodyData = { blocks: [{ type: 'ordered-list-item', depth: 1 }] }; 52 | const result = getBlocks({ contentState: bodyData }); 53 | expect(result[0].props.children[1].props.counter).toBe(1); 54 | }); 55 | 56 | it('OrderedListItem when depth is two', () => { 57 | const bodyData = { blocks: [{ type: 'ordered-list-item', depth: 2 }] }; 58 | const result = getBlocks({ contentState: bodyData }); 59 | expect(result[0].props.children[1].props.counter).toBe(1); 60 | }); 61 | 62 | it('OrderedListItem when is second item', () => { 63 | const bodyData = { 64 | blocks: [ 65 | { 66 | text: 'first', 67 | type: 'ordered-list-item', 68 | depth: 0, 69 | }, 70 | { 71 | text: 'second', 72 | type: 'ordered-list-item', 73 | depth: 0, 74 | }, 75 | ], 76 | }; 77 | const result = getBlocks({ contentState: bodyData }); 78 | expect(result[0].props.children[1].props.counter).toBe(1); 79 | expect(result[1].props.children[1].props.counter).toBe(2); 80 | }); 81 | 82 | it('OrderedListItem when is first item has two children', () => { 83 | const bodyData = { 84 | blocks: [ 85 | { 86 | text: 'mother', 87 | type: 'ordered-list-item', 88 | depth: 0, 89 | }, 90 | { 91 | text: 'first', 92 | type: 'ordered-list-item', 93 | depth: 1, 94 | }, 95 | { 96 | text: 'second', 97 | type: 'ordered-list-item', 98 | depth: 1, 99 | }, 100 | ], 101 | }; 102 | const result = getBlocks({ contentState: bodyData }); 103 | expect(result[0].props.children[1].props.counter).toBe(1); 104 | expect(result[1].props.children[1].props.counter).toBe(1); 105 | expect(result[2].props.children[1].props.counter).toBe(2); 106 | }); 107 | 108 | it('OrderedListItem when is second item has two children', () => { 109 | const bodyData = { 110 | blocks: [ 111 | { 112 | text: 'first', 113 | type: 'ordered-list-item', 114 | depth: 0, 115 | }, 116 | { 117 | text: 'mother', 118 | type: 'ordered-list-item', 119 | depth: 0, 120 | }, 121 | { 122 | text: 'first', 123 | type: 'ordered-list-item', 124 | depth: 1, 125 | }, 126 | { 127 | text: 'second', 128 | type: 'ordered-list-item', 129 | depth: 1, 130 | }, 131 | ], 132 | }; 133 | const result = getBlocks({ contentState: bodyData }); 134 | expect(result[0].props.children[1].props.counter).toBe(1); 135 | expect(result[1].props.children[1].props.counter).toBe(2); 136 | expect(result[2].props.children[1].props.counter).toBe(1); 137 | expect(result[3].props.children[1].props.counter).toBe(2); 138 | }); 139 | 140 | it('OrderedListItem when there are multiple OrderedLists', () => { 141 | const bodyData = { 142 | blocks: [ 143 | { 144 | text: 'mother', 145 | type: 'ordered-list-item', 146 | depth: 0, 147 | }, 148 | { 149 | text: 'first', 150 | type: 'ordered-list-item', 151 | depth: 1, 152 | }, 153 | { 154 | text: '', 155 | type: 'unstyled', 156 | }, 157 | { 158 | text: 'new first', 159 | type: 'ordered-list-item', 160 | depth: 0, 161 | }, 162 | { 163 | text: 'new second', 164 | type: 'ordered-list-item', 165 | depth: 0, 166 | }, 167 | ], 168 | }; 169 | const result = getBlocks({ contentState: bodyData }); 170 | expect(result[0].props.children[1].props.counter).toBe(1); 171 | expect(result[1].props.children[1].props.counter).toBe(1); 172 | expect(result[3].props.children[1].props.counter).toBe(1); 173 | expect(result[4].props.children[1].props.counter).toBe(2); 174 | }); 175 | 176 | it('getBlocks when multiple list types', () => { 177 | const bodyData = { 178 | blocks: [ 179 | { type: 'ordered-list-item' }, { type: 'unordered-list-item' }, 180 | { type: 'ordered-list-item' }, { type: 'unordered-list-item' }, 181 | ], 182 | }; 183 | const result = getBlocks({ contentState: bodyData }); 184 | expect(result[3].props.children[1].type).toBe('UnorderedListItem'); 185 | }); 186 | 187 | it('getBlocks with mixed types one being a list', () => { 188 | const bodyData = { 189 | blocks: [ 190 | { type: 'ordered-list-item' }, { type: 'blockquote' }, 191 | ], 192 | }; 193 | const result = getBlocks({ contentState: bodyData }); 194 | expect(result[1].props.children[1].type).toBe('BlockQuote'); 195 | }); 196 | 197 | it('atomicHandler function when type atomic', () => { 198 | const bodyData = { blocks: [{ type: 'atomic' }] }; 199 | const atomicHandler = item => item; 200 | const result = getBlocks({ contentState: bodyData, atomicHandler }); 201 | expect(result[0].type).toBe('atomic'); 202 | }); 203 | 204 | it('calls atomicHandler with correctly params', () => { 205 | const bodyData = { blocks: [{ type: 'atomic' }], entityMap: {} }; 206 | const atomicHandler = jest.fn(); 207 | getBlocks({ contentState: bodyData, atomicHandler }); 208 | expect(atomicHandler.mock.calls[0].length).toBe(2); 209 | }); 210 | 211 | it('returns the item if do not have a atomicHandler', () => { 212 | const bodyData = { blocks: [{ type: 'atomic', test: 'ok' }], entityMap: {} }; 213 | const result = getBlocks({ contentState: bodyData }); 214 | expect(result[0].test).toBe('ok'); 215 | }); 216 | 217 | it('atomicHandler function when type atomic between lists', () => { 218 | const bodyData = { 219 | blocks: [ 220 | { type: 'ordered-list-item' }, { type: 'atomic' }, { type: 'ordered-list-item' }, 221 | ], 222 | }; 223 | const atomicHandler = item => item; 224 | const result = getBlocks({ contentState: bodyData, atomicHandler }); 225 | expect(result[1].props.children[1].type).toBe('atomic'); 226 | }); 227 | 228 | it('array of null when type is invalid', () => { 229 | const bodyData = { blocks: [{ type: 'my-own-type' }] }; 230 | const result = getBlocks({ contentState: bodyData }); 231 | expect(result[0].props.children).toBe(null); 232 | }); 233 | 234 | it('null when bodyData doesn\'t have blocks', () => { 235 | const bodyData = { data: 'other-data' }; 236 | const result = getBlocks({ contentState: bodyData }); 237 | expect(result).toBe(null); 238 | }); 239 | 240 | it('should use the optional customBlockHandler when handling custom block types', () => { 241 | const bodyData = { blocks: [{ type: 'my-own-type' }] }; 242 | const myCustomComponent = jest.fn(); 243 | const customBlockHandler = jest.fn(() => myCustomComponent); 244 | const result = getBlocks({ contentState: bodyData, customBlockHandler }); 245 | expect(customBlockHandler.mock.calls.length).toBe(1); 246 | expect(customBlockHandler.mock.calls[0][0].type).toBe('my-own-type'); 247 | expect(customBlockHandler.mock.calls[0][1].contentState).toBe(bodyData); 248 | expect(customBlockHandler.mock.calls[0][1].customBlockHandler).toBe(customBlockHandler); 249 | expect(result[0]).toBe(myCustomComponent); 250 | }); 251 | 252 | test('pass text props to ', () => { 253 | const contentState = { 254 | blocks: [ 255 | { type: 'blockquote', text: 'My text' }, 256 | { type: 'unstyled', text: 'My text' }, 257 | ], 258 | }; 259 | const result = getBlocks({ contentState, textProps: { selectable: true } }); 260 | expect(result[0].props.children[1].props.textProps.selectable).toBe(true); 261 | expect(result[1].props.children[1].props.textProps.selectable).toBe(true); 262 | }); 263 | }); 264 | 265 | describe('ViewAfterList', () => { 266 | it('should pass props', () => { 267 | const tree = renderer.create().toJSON(); 268 | expect(tree).toMatchSnapshot(); 269 | }); 270 | }); 271 | -------------------------------------------------------------------------------- /sample/__tests__/helpers/getItemType.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | /* eslint-env jest */ 8 | 9 | import getItemType from '../../../src/helpers/getItemType'; 10 | 11 | it('returns empty string if object doesnt have style attribute', () => { 12 | const mock = {}; 13 | const result = getItemType(mock); 14 | expect(result).toEqual(''); 15 | }); 16 | 17 | it('returns lowercase if style exists but item isnt an array', () => { 18 | const mock = { style: 'LINK' }; 19 | const result = getItemType(mock); 20 | expect(result).toEqual('link'); 21 | }); 22 | 23 | it('returns lowercase array if style exists but item is an array', () => { 24 | const mock = { style: ['LINK', 'BOLD'] }; 25 | const result = getItemType(mock); 26 | expect(result).toEqual(['link', 'bold']); 27 | }); 28 | -------------------------------------------------------------------------------- /sample/__tests__/helpers/isEmptyObject.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | /* eslint-env jest */ 8 | 9 | import isEmptyObject from '../../../src/helpers/isEmptyObject'; 10 | 11 | it('returns true if object is empty', () => { 12 | const mock = {}; 13 | const result = isEmptyObject(mock); 14 | expect(result).toEqual(true); 15 | }); 16 | 17 | it('returns false if object is empty', () => { 18 | const mock = { a: 1 }; 19 | const result = isEmptyObject(mock); 20 | expect(result).toEqual(false); 21 | }); 22 | -------------------------------------------------------------------------------- /sample/__tests__/loadAttributes.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | /* eslint-env jest */ 8 | 9 | import loadAttributes, { getItemOnPress } from '../../src/loadAttributes'; 10 | 11 | describe('getItemOnPress()', () => { 12 | test('returns the right function', () => { 13 | const navigate = jest.fn(); 14 | const resultFn = getItemOnPress( 15 | { key: 'test' }, 16 | { test: { data: { url: 'http://ok' } } }, 17 | navigate, 18 | ); 19 | resultFn(); 20 | expect(navigate.mock.calls.length).toBe(1); 21 | }); 22 | 23 | test('returns the right function', () => { 24 | expect(getItemOnPress({})).toBe(); 25 | }); 26 | }); 27 | 28 | it('returns only text if other objects are empty', () => { 29 | const params = { 30 | text: 'Hello World', 31 | inlineStyles: [], 32 | entityMap: {}, 33 | entityRanges: [], 34 | }; 35 | const mock = ['Hello World']; 36 | const result = loadAttributes(params); 37 | expect(result).toEqual(mock); 38 | }); 39 | 40 | it('still works with no inlineStyles object', () => { 41 | const params = { 42 | text: 'Hello World', 43 | entityMap: {}, 44 | entityRanges: [], 45 | }; 46 | const mock = ['Hello World']; 47 | const result = loadAttributes(params); 48 | expect(result).toEqual(mock); 49 | }); 50 | 51 | it('have correct length with inlineStyles and text', () => { 52 | const params = { 53 | text: 'Hello World', 54 | inlineStyles: [ 55 | { 56 | offset: 2, 57 | length: 5, 58 | style: 'BOLD', 59 | }, 60 | ], 61 | entityMap: {}, 62 | entityRanges: [], 63 | }; 64 | const result = loadAttributes(params); 65 | expect(result).toHaveLength(3); 66 | }); 67 | 68 | it('have correct length with inlineStyles and text width astral symbols', () => { 69 | const params = { 70 | text: 'Iñtërnâtiônàlizætiøn☃💩 Etiama nisi augue ultricie qa magna', 71 | inlineStyles: [ 72 | { 73 | offset: 4, 74 | length: 35, 75 | style: 'BOLD', 76 | }, 77 | ], 78 | entityMap: {}, 79 | entityRanges: [], 80 | }; 81 | const result = loadAttributes(params); 82 | expect(result).toHaveLength(3); 83 | }); 84 | 85 | it('have correct length with multiple inlineStyles and text', () => { 86 | const params = { 87 | text: 'Hello World Hello World Hello World', 88 | inlineStyles: [ 89 | { 90 | offset: 2, 91 | length: 5, 92 | style: 'BOLD', 93 | }, 94 | { 95 | offset: 6, 96 | length: 3, 97 | style: 'ITALIC', 98 | }, 99 | ], 100 | entityMap: {}, 101 | entityRanges: [], 102 | }; 103 | const result = loadAttributes(params); 104 | expect(result).toHaveLength(5); 105 | }); 106 | 107 | it('have correct length with inlineStyles, entityMap and text', () => { 108 | const params = { 109 | text: 'Hello World Hello World Hello World', 110 | inlineStyles: [{ 111 | offset: 2, 112 | length: 5, 113 | style: 'BOLD', 114 | }], 115 | entityMap: { 116 | 0: { 117 | type: 'LINK', 118 | mutability: 'MUTABLE', 119 | data: { 120 | url: 'https://github.com/globocom/react-native-draftjs-render', 121 | }, 122 | }, 123 | }, 124 | entityRanges: [{ 125 | offset: 0, 126 | length: 5, 127 | key: 0, 128 | }], 129 | }; 130 | const result = loadAttributes(params); 131 | expect(result).toHaveLength(4); 132 | const typeOfFunc = typeof result[0].props.onPress; 133 | expect(typeOfFunc).toBe('function'); 134 | }); 135 | 136 | it('have correct length with multiple inlineStyles and text with substring without style', () => { 137 | const params = { 138 | text: 'Hello World Hello World Hello World', 139 | inlineStyles: [ 140 | { 141 | offset: 2, 142 | length: 3, 143 | style: 'BOLD', 144 | }, 145 | { 146 | offset: 7, 147 | length: 3, 148 | style: 'ITALIC', 149 | }, 150 | { 151 | offset: 7, 152 | length: 3, 153 | style: 'LINK', 154 | }, 155 | ], 156 | entityMap: { 157 | 0: { 158 | type: 'LINK', 159 | mutability: 'MUTABLE', 160 | data: { 161 | url: 'https://github.com/globocom/react-native-draftjs-render', 162 | }, 163 | }, 164 | }, 165 | entityRanges: [], 166 | }; 167 | const result = loadAttributes(params); 168 | expect(result).toHaveLength(5); 169 | expect(result[4].props.children).toBe('d Hello World Hello World'); 170 | }); 171 | 172 | it('have correct length with multiple inlineStyles and text with substring without style', () => { 173 | const params = { 174 | text: 'Hello World Hello World Hello World', 175 | inlineStyles: [{ 176 | offset: 300, 177 | length: 2, 178 | style: 'BOLD', 179 | }], 180 | entityMap: {}, 181 | entityRanges: [], 182 | }; 183 | const result = loadAttributes(params); 184 | expect(result).toHaveLength(2); 185 | expect(result[0].props.children).toBe(params.text); 186 | }); 187 | 188 | it('have inlineStyles with substring and type is given', () => { 189 | const params = { 190 | text: 'Hello World Hello World Hello World', 191 | inlineStyles: [{ 192 | offset: 300, 193 | length: 2, 194 | style: 'BOLD', 195 | }], 196 | entityMap: {}, 197 | entityRanges: [], 198 | type: 'unstyled', 199 | }; 200 | const result = loadAttributes(params); 201 | expect(result).toHaveLength(2); 202 | expect(result[0].props.children).toBe(params.text); 203 | }); 204 | 205 | 206 | it('have inlineStyles with substring and type is given with proper customStyles to that type', () => { 207 | const params = { 208 | text: 'Hello World Hello World Hello World', 209 | inlineStyles: [{ 210 | offset: 300, 211 | length: 2, 212 | style: 'BOLD', 213 | }], 214 | entityMap: {}, 215 | entityRanges: [], 216 | type: 'unstyled', 217 | customStyles: { 218 | unstyled: { 219 | lineHeight: 30, 220 | }, 221 | }, 222 | }; 223 | const result = loadAttributes(params); 224 | expect(result).toHaveLength(2); 225 | expect(result[0].props.children).toBe(params.text); 226 | }); 227 | 228 | it('have inlineStyles with substring and type is given without proper customStyles to that type', () => { 229 | const params = { 230 | text: 'Hello World Hello World Hello World', 231 | inlineStyles: [{ 232 | offset: 300, 233 | length: 2, 234 | style: 'BOLD', 235 | }], 236 | entityMap: {}, 237 | entityRanges: [], 238 | type: 'unstyled', 239 | customStyles: { 240 | other: { 241 | lineHeight: 30, 242 | }, 243 | }, 244 | }; 245 | const result = loadAttributes(params); 246 | expect(result).toHaveLength(2); 247 | expect(result[0].props.children).toBe(params.text); 248 | }); 249 | 250 | it('have inlineStyles with substring and type is given without lineHeight customStyles to that type', () => { 251 | const params = { 252 | text: 'Hello World Hello World Hello World', 253 | inlineStyles: [{ 254 | offset: 300, 255 | length: 2, 256 | style: 'BOLD', 257 | }], 258 | entityMap: {}, 259 | entityRanges: [], 260 | type: 'unstyled', 261 | customStyles: { 262 | unstyled: { 263 | fontSize: 30, 264 | }, 265 | }, 266 | }; 267 | const result = loadAttributes(params); 268 | expect(result).toHaveLength(2); 269 | expect(result[0].props.children).toBe(params.text); 270 | }); 271 | 272 | it('have entityRanges but undefined entityMap', () => { 273 | const params = { 274 | text: 'Hello World', 275 | inlineStyles: [], 276 | entityMap: undefined, 277 | entityRanges: [{ 278 | offset: 0, 279 | length: 5, 280 | key: 0, 281 | }], 282 | type: 'unstyled', 283 | }; 284 | const result = loadAttributes(params); 285 | expect(result).toHaveLength(2); 286 | 287 | const typeOfFunc = typeof result[0].props.onPress; 288 | expect(typeOfFunc).toBe('undefined'); 289 | }); 290 | 291 | it('have entityRanges but empty object entityMap', () => { 292 | const params = { 293 | text: 'Hello World', 294 | inlineStyles: [], 295 | entityMap: {}, 296 | entityRanges: [{ 297 | offset: 0, 298 | length: 5, 299 | key: 0, 300 | }], 301 | type: 'unstyled', 302 | }; 303 | const result = loadAttributes(params); 304 | expect(result).toHaveLength(2); 305 | 306 | const typeOfFunc = typeof result[0].props.onPress; 307 | expect(typeOfFunc).toBe('undefined'); 308 | }); 309 | -------------------------------------------------------------------------------- /sample/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.react_native_draftjs_render', 50 | ) 51 | 52 | android_resource( 53 | name = 'res', 54 | res = 'src/main/res', 55 | package = 'com.react_native_draftjs_render', 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 | -------------------------------------------------------------------------------- /sample/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation 19 | * entryFile: "index.android.js", 20 | * 21 | * // whether to bundle JS and assets in debug mode 22 | * bundleInDebug: false, 23 | * 24 | * // whether to bundle JS and assets in release mode 25 | * bundleInRelease: true, 26 | * 27 | * // whether to bundle JS and assets in another build variant (if configured). 28 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 29 | * // The configuration property can be in the following formats 30 | * // 'bundleIn${productFlavor}${buildType}' 31 | * // 'bundleIn${buildType}' 32 | * // bundleInFreeDebug: true, 33 | * // bundleInPaidRelease: true, 34 | * // bundleInBeta: true, 35 | * 36 | * // the root of your project, i.e. where "package.json" lives 37 | * root: "../../", 38 | * 39 | * // where to put the JS bundle asset in debug mode 40 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 41 | * 42 | * // where to put the JS bundle asset in release mode 43 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 44 | * 45 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 46 | * // require('./image.png')), in debug mode 47 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 48 | * 49 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 50 | * // require('./image.png')), in release mode 51 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 52 | * 53 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 54 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 55 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 56 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 57 | * // for example, you might want to remove it from here. 58 | * inputExcludes: ["android/**", "ios/**"], 59 | * 60 | * // override which node gets called and with what additional arguments 61 | * nodeExecutableAndArgs: ["node"] 62 | * 63 | * // supply additional arguments to the packager 64 | * extraPackagerArgs: [] 65 | * ] 66 | */ 67 | 68 | project.ext.react = [ 69 | entryFile: "index.js" 70 | ] 71 | 72 | apply from: "../../node_modules/react-native/react.gradle" 73 | 74 | /** 75 | * Set this to true to create two separate APKs instead of one: 76 | * - An APK that only works on ARM devices 77 | * - An APK that only works on x86 devices 78 | * The advantage is the size of the APK is reduced by about 4MB. 79 | * Upload all the APKs to the Play Store and people will download 80 | * the correct one based on the CPU architecture of their device. 81 | */ 82 | def enableSeparateBuildPerCPUArchitecture = false 83 | 84 | /** 85 | * Run Proguard to shrink the Java bytecode in release builds. 86 | */ 87 | def enableProguardInReleaseBuilds = false 88 | 89 | android { 90 | compileSdkVersion 23 91 | buildToolsVersion "23.0.1" 92 | 93 | defaultConfig { 94 | applicationId "com.react_native_draftjs_render" 95 | minSdkVersion 16 96 | targetSdkVersion 22 97 | versionCode 1 98 | versionName "1.0" 99 | ndk { 100 | abiFilters "armeabi-v7a", "x86" 101 | } 102 | } 103 | splits { 104 | abi { 105 | reset() 106 | enable enableSeparateBuildPerCPUArchitecture 107 | universalApk false // If true, also generate a universal APK 108 | include "armeabi-v7a", "x86" 109 | } 110 | } 111 | buildTypes { 112 | release { 113 | minifyEnabled enableProguardInReleaseBuilds 114 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 115 | } 116 | } 117 | // applicationVariants are e.g. debug, release 118 | applicationVariants.all { variant -> 119 | variant.outputs.each { output -> 120 | // For each separate APK per architecture, set a unique version code as described here: 121 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 122 | def versionCodes = ["armeabi-v7a":1, "x86":2] 123 | def abi = output.getFilter(OutputFile.ABI) 124 | if (abi != null) { // null for the universal-debug, universal-release variants 125 | output.versionCodeOverride = 126 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 127 | } 128 | } 129 | } 130 | } 131 | 132 | dependencies { 133 | compile fileTree(dir: "libs", include: ["*.jar"]) 134 | compile "com.android.support:appcompat-v7:23.0.1" 135 | compile "com.facebook.react:react-native:+" // From node_modules 136 | } 137 | 138 | // Run this once to be able to run the application with BUCK 139 | // puts all compile dependencies into folder libs for BUCK to use 140 | task copyDownloadableDepsToLibs(type: Copy) { 141 | from configurations.compile 142 | into 'libs' 143 | } 144 | -------------------------------------------------------------------------------- /sample/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Disabling obfuscation is useful if you collect stack traces from production crashes 20 | # (unless you are using a system that supports de-obfuscate the stack traces). 21 | -dontobfuscate 22 | 23 | # React Native 24 | 25 | # Keep our interfaces so they can be used by other ProGuard rules. 26 | # See http://sourceforge.net/p/proguard/bugs/466/ 27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip 30 | 31 | # Do not strip any method/class that is annotated with @DoNotStrip 32 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 33 | -keep @com.facebook.common.internal.DoNotStrip class * 34 | -keepclassmembers class * { 35 | @com.facebook.proguard.annotations.DoNotStrip *; 36 | @com.facebook.common.internal.DoNotStrip *; 37 | } 38 | 39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 40 | void set*(***); 41 | *** get*(); 42 | } 43 | 44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 46 | -keepclassmembers,includedescriptorclasses class * { native ; } 47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } 49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } 50 | 51 | -dontwarn com.facebook.react.** 52 | 53 | # okhttp 54 | 55 | -keepattributes Signature 56 | -keepattributes *Annotation* 57 | -keep class okhttp3.** { *; } 58 | -keep interface okhttp3.** { *; } 59 | -dontwarn okhttp3.** 60 | 61 | # okio 62 | 63 | -keep class sun.misc.Unsafe { *; } 64 | -dontwarn java.nio.file.* 65 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 66 | -dontwarn okio.** 67 | -------------------------------------------------------------------------------- /sample/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | 19 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /sample/android/app/src/main/java/com/react_native_draftjs_render/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.react_native_draftjs_render; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. 9 | * This is used to schedule rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "react_native_draftjs_render"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sample/android/app/src/main/java/com/react_native_draftjs_render/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.react_native_draftjs_render; 2 | 3 | import android.app.Application; 4 | 5 | import com.facebook.react.ReactApplication; 6 | import com.facebook.react.ReactNativeHost; 7 | import com.facebook.react.ReactPackage; 8 | import com.facebook.react.shell.MainReactPackage; 9 | import com.facebook.soloader.SoLoader; 10 | 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | public class MainApplication extends Application implements ReactApplication { 15 | 16 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 17 | @Override 18 | public boolean getUseDeveloperSupport() { 19 | return BuildConfig.DEBUG; 20 | } 21 | 22 | @Override 23 | protected String getJSMainModuleName() { 24 | return "index"; 25 | } 26 | 27 | @Override 28 | protected List getPackages() { 29 | return Arrays.asList( 30 | new MainReactPackage() 31 | ); 32 | } 33 | }; 34 | 35 | @Override 36 | public ReactNativeHost getReactNativeHost() { 37 | return mReactNativeHost; 38 | } 39 | 40 | @Override 41 | public void onCreate() { 42 | super.onCreate(); 43 | SoLoader.init(this, /* native exopackage */ false); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sample/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/globocom/react-native-draftjs-render/ce93af97b2c23f144c70dbc1fab9df8475500828/sample/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/globocom/react-native-draftjs-render/ce93af97b2c23f144c70dbc1fab9df8475500828/sample/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/globocom/react-native-draftjs-render/ce93af97b2c23f144c70dbc1fab9df8475500828/sample/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/globocom/react-native-draftjs-render/ce93af97b2c23f144c70dbc1fab9df8475500828/sample/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | react_native_draftjs_render 3 | 4 | -------------------------------------------------------------------------------- /sample/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /sample/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | mavenLocal() 18 | jcenter() 19 | maven { 20 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 21 | url "$rootDir/../node_modules/react-native/android" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useDeprecatedNdk=true 21 | -------------------------------------------------------------------------------- /sample/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/globocom/react-native-draftjs-render/ce93af97b2c23f144c70dbc1fab9df8475500828/sample/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sample/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 6 | -------------------------------------------------------------------------------- /sample/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 | -------------------------------------------------------------------------------- /sample/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 | -------------------------------------------------------------------------------- /sample/android/keystores/BUCK: -------------------------------------------------------------------------------- 1 | keystore( 2 | name = 'debug', 3 | store = 'debug.keystore', 4 | properties = 'debug.keystore.properties', 5 | visibility = [ 6 | 'PUBLIC', 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /sample/android/keystores/debug.keystore.properties: -------------------------------------------------------------------------------- 1 | key.store=debug.keystore 2 | key.alias=androiddebugkey 3 | key.store.password=android 4 | key.alias.password=android 5 | -------------------------------------------------------------------------------- /sample/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'react_native_draftjs_render' 2 | 3 | include ':app' 4 | -------------------------------------------------------------------------------- /sample/babel.config.js: -------------------------------------------------------------------------------- 1 | const babelFunction = (api) => { 2 | const presets = [ 3 | 'module:metro-react-native-babel-preset', 4 | ]; 5 | api.cache.never(); 6 | return { 7 | presets, 8 | }; 9 | }; 10 | 11 | module.exports = babelFunction; 12 | -------------------------------------------------------------------------------- /sample/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | 8 | // @flow 9 | 10 | import React from 'react'; // eslint-disable-line no-unused-vars 11 | import { AppRegistry } from 'react-native'; 12 | 13 | import App from './src'; 14 | 15 | AppRegistry.registerComponent('react_native_draftjs_render', (): any => App); 16 | -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_render-tvOS/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 | NSExceptionDomains 45 | 46 | localhost 47 | 48 | NSExceptionAllowsInsecureHTTPLoads 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_render-tvOSTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_render.xcodeproj/xcshareddata/xcschemes/react_native_draftjs_render-tvOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 61 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 92 | 94 | 100 | 101 | 102 | 103 | 104 | 105 | 111 | 113 | 119 | 120 | 121 | 122 | 124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_render.xcodeproj/xcshareddata/xcschemes/react_native_draftjs_render.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 61 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 92 | 94 | 100 | 101 | 102 | 103 | 104 | 105 | 111 | 113 | 119 | 120 | 121 | 122 | 124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_render/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 | -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_render/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 13 | #import 14 | 15 | @implementation AppDelegate 16 | 17 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 18 | { 19 | NSURL *jsCodeLocation; 20 | 21 | jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; 22 | 23 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 24 | moduleName:@"react_native_draftjs_render" 25 | initialProperties:nil 26 | launchOptions:launchOptions]; 27 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 28 | 29 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 30 | UIViewController *rootViewController = [UIViewController new]; 31 | rootViewController.view = rootView; 32 | self.window.rootViewController = rootViewController; 33 | [self.window makeKeyAndVisible]; 34 | return YES; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_render/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 | -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_render/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 | } -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_render/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 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 | NSAppTransportSecurity 26 | 27 | NSExceptionDomains 28 | 29 | localhost 30 | 31 | NSExceptionAllowsInsecureHTTPLoads 32 | 33 | 34 | 35 | 36 | NSLocationWhenInUseUsageDescription 37 | 38 | UILaunchStoryboardName 39 | LaunchScreen 40 | UIRequiredDeviceCapabilities 41 | 42 | armv7 43 | 44 | UISupportedInterfaceOrientations 45 | 46 | UIInterfaceOrientationPortrait 47 | UIInterfaceOrientationLandscapeLeft 48 | UIInterfaceOrientationLandscapeRight 49 | 50 | UIViewControllerBasedStatusBarAppearance 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_render/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 | -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_renderTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /sample/ios/react_native_draftjs_renderTests/react_native_draftjs_renderTests.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 | #import 12 | 13 | #import 14 | #import 15 | 16 | #define TIMEOUT_SECONDS 600 17 | #define TEXT_TO_LOOK_FOR @"Welcome to React Native!" 18 | 19 | @interface react_native_draftjs_renderTests : XCTestCase 20 | 21 | @end 22 | 23 | @implementation react_native_draftjs_renderTests 24 | 25 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test 26 | { 27 | if (test(view)) { 28 | return YES; 29 | } 30 | for (UIView *subview in [view subviews]) { 31 | if ([self findSubviewInView:subview matching:test]) { 32 | return YES; 33 | } 34 | } 35 | return NO; 36 | } 37 | 38 | - (void)testRendersWelcomeScreen 39 | { 40 | UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; 41 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 42 | BOOL foundElement = NO; 43 | 44 | __block NSString *redboxError = nil; 45 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 46 | if (level >= RCTLogLevelError) { 47 | redboxError = message; 48 | } 49 | }); 50 | 51 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 52 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 53 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 54 | 55 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { 56 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 57 | return YES; 58 | } 59 | return NO; 60 | }]; 61 | } 62 | 63 | RCTSetLogFunction(RCTDefaultLogFunction); 64 | 65 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 66 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 67 | } 68 | 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /sample/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start", 7 | "test": "jest", 8 | "test-reset": "jest --updateSnapshot", 9 | "sync-lib": "sync-files ../src/ react-native-draftjs-render/src/; sync-files ../index.js react-native-draftjs-render/index.js", 10 | "watch-src": "sync-files --watch ../src/ react-native-draftjs-render/src/", 11 | "watch-index": "sync-files --watch ../index.js react-native-draftjs-render/index.js" 12 | }, 13 | "dependencies": { 14 | "react": "16.6.3", 15 | "react-native": "0.57.8", 16 | "stringz": "1.0.0" 17 | }, 18 | "devDependencies": { 19 | "@babel/core": "7.2.2", 20 | "babel-core": "7.0.0-bridge.0", 21 | "babel-jest": "23.6.0", 22 | "metro-react-native-babel-preset": "0.51.1", 23 | "jest": "23.6.0", 24 | "react-test-renderer": "16.6.3", 25 | "sync-files": "1.0.3" 26 | }, 27 | "jest": { 28 | "preset": "react-native" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/src/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | import React from 'react'; 10 | import { 11 | StyleSheet, 12 | ScrollView, 13 | Image, 14 | View, 15 | } from 'react-native'; 16 | 17 | import getRNDraftJSBlocks from '../react-native-draftjs-render'; 18 | 19 | import data from './resourceMock.json'; 20 | 21 | const styles = StyleSheet.create({ 22 | container: { 23 | flex: 1, 24 | paddingHorizontal: 16, 25 | marginTop: 32, 26 | backgroundColor: '#f4f4f4', 27 | }, 28 | }); 29 | 30 | const customStyles = StyleSheet.flatten({ 31 | unstyled: { 32 | fontSize: 18, 33 | fontWeight: 'normal', 34 | letterSpacing: -0.75, 35 | lineHeight: 32, 36 | marginBottom: 21, 37 | }, 38 | link: { 39 | color: '#c4170c', 40 | fontWeight: 'bold', 41 | textDecorationLine: 'none', 42 | }, 43 | unorderedListItemContainer: { 44 | marginBottom: 16, 45 | position: 'relative', 46 | }, 47 | unorderedListItemBullet: { 48 | marginRight: 18, 49 | position: 'relative', 50 | top: 14, 51 | width: 6, 52 | height: 6, 53 | alignSelf: 'flex-start', 54 | }, 55 | 'unordered-list-item': { 56 | fontSize: 18, 57 | lineHeight: 32, 58 | alignSelf: 'flex-start', 59 | flex: 1, 60 | }, 61 | orderedListContainer: { 62 | marginBottom: 16, 63 | }, 64 | orderedListItemNumber: { 65 | fontSize: 18, 66 | lineHeight: 32, 67 | marginRight: 11, 68 | alignSelf: 'flex-start', 69 | color: '#c4170c', 70 | }, 71 | 'ordered-list-item': { 72 | alignSelf: 'flex-start', 73 | fontSize: 18, 74 | lineHeight: 32, 75 | flex: 1, 76 | }, 77 | 'code-block': { 78 | backgroundColor: '#e2e2e2', 79 | }, 80 | blockquote: { 81 | fontWeight: 'bold', 82 | color: '#333', 83 | lineHeight: 33, 84 | paddingTop: 24, 85 | marginBottom: 24, 86 | fontSize: 33, 87 | letterSpacing: -2, 88 | }, 89 | viewAfterList: { 90 | marginBottom: 32, 91 | }, 92 | }); 93 | 94 | const atomicHandler = (item: Object): any => { 95 | switch (item.data.type) { 96 | case 'image': 97 | return ( 98 | 99 | 103 | 104 | ); 105 | default: 106 | return null; 107 | } 108 | }; 109 | 110 | export default function App(): any { 111 | const params = { 112 | contentState: data, 113 | customStyles, 114 | atomicHandler, 115 | depthMargin: 32, 116 | textProps: { 117 | selectable: true, 118 | }, 119 | }; 120 | const blocks = getRNDraftJSBlocks(params); 121 | 122 | return ( 123 | 124 | {blocks} 125 | 126 | ); 127 | } 128 | -------------------------------------------------------------------------------- /sample/src/resourceMock.json: -------------------------------------------------------------------------------- 1 | { 2 | "blocks": [ 3 | { 4 | "entityRanges": [], 5 | "depth": 0, 6 | "data": {}, 7 | "inlineStyleRanges": [], 8 | "text": "Maecenas nec odio", 9 | "type": "header-one", 10 | "key": "ad9sdfdg5" 11 | }, 12 | { 13 | "key": "5r867", 14 | "text": "Etiam ultricies nisi vel augue. Sed magna purus, fermentum eu, tincidunt eu, varius ut, felis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Cras dapibus. Sed mollis, eros et ultrices tempus, mauris ipsum aliquam libero, non adipiscing dolor urna a orci.", 15 | "type": "unstyled", 16 | "depth": 0, 17 | "inlineStyleRanges": [ 18 | { 19 | "offset": 25, 20 | "length": 5, 21 | "style": "BOLD" 22 | }, 23 | { 24 | "offset": 307, 25 | "length": 10, 26 | "style": "BOLD" 27 | }, 28 | { 29 | "offset": 241, 30 | "length": 6, 31 | "style": "ITALIC" 32 | } 33 | ], 34 | "entityRanges": [], 35 | "data": {} 36 | }, 37 | { 38 | "key": "3lkq2", 39 | "text": "Ma 🎤Iñtërnâtiônàlizætiøn☃💩 Etiama nia", 40 | "type": "unstyled", 41 | "depth": 0, 42 | "inlineStyleRanges": [], 43 | "entityRanges": [ 44 | { 45 | "offset": 2, 46 | "length": 35, 47 | "key": 0 48 | } 49 | ], 50 | "data": {} 51 | }, 52 | { 53 | "key": "7noje", 54 | "text": "🎤 Etiama augue 'ultricie ultric'", 55 | "type": "unstyled", 56 | "depth": 0, 57 | "inlineStyleRanges": [], 58 | "entityRanges": [ 59 | { 60 | "offset": 1, 61 | "length": 31, 62 | "key": 0 63 | } 64 | ], 65 | "data": {} 66 | }, 67 | { 68 | "key": "5r864123", 69 | "text": "Etiam ultricies nisi vel augue.", 70 | "type": "unstyled", 71 | "depth": 0, 72 | "inlineStyleRanges": [], 73 | "entityRanges": [ 74 | { 75 | "offset": 0, 76 | "length": 5, 77 | "key": 0 78 | } 79 | ], 80 | "data": {} 81 | }, 82 | { 83 | "key": "5r8641253", 84 | "text": "Etiam ultricies nisi vel augue vel augue vel augue.", 85 | "type": "unstyled", 86 | "depth": 0, 87 | "inlineStyleRanges": [ 88 | { 89 | "offset": 0, 90 | "length": 5, 91 | "style": "BOLD" 92 | } 93 | ], 94 | "entityRanges": [], 95 | "data": {} 96 | }, 97 | { 98 | "key": "5r8641", 99 | "text": "Etiam ultricies nisi vel augue.", 100 | "type": "unstyled", 101 | "depth": 0, 102 | "inlineStyleRanges": [ 103 | { 104 | "offset": 7, 105 | "length": 9, 106 | "style": "BOLD" 107 | }, 108 | { 109 | "offset": 7, 110 | "length": 10, 111 | "style": "ITALIC" 112 | } 113 | ], 114 | "entityRanges": [], 115 | "data": {} 116 | }, 117 | { 118 | "key": "3tvln", 119 | "text": "", 120 | "type": "atomic", 121 | "depth": 0, 122 | "inlineStyleRanges": [], 123 | "entityRanges": [], 124 | "data": { 125 | "type": "image", 126 | "url": "https://lorempixel.com/400/200/" 127 | } 128 | }, 129 | { 130 | "entityRanges": [], 131 | "depth": 0, 132 | "data": {}, 133 | "inlineStyleRanges": [], 134 | "text": "Aenean leo ligula porttitor", 135 | "type": "header-two", 136 | "key": "c87fd" 137 | }, 138 | { 139 | "entityRanges": [], 140 | "depth": 0, 141 | "data": {}, 142 | "inlineStyleRanges": [], 143 | "text": "Morbi vestibulum volutpat", 144 | "type": "header-three", 145 | "key": "c9mft" 146 | }, 147 | { 148 | "entityRanges": [], 149 | "depth": 0, 150 | "data": {}, 151 | "inlineStyleRanges": [], 152 | "text": "Class aptent taciti sociosqu", 153 | "type": "header-four", 154 | "key": "ad9sdsdfdg5sd" 155 | }, 156 | { 157 | "entityRanges": [], 158 | "depth": 0, 159 | "data": {}, 160 | "inlineStyleRanges": [], 161 | "text": "Phasellus leo dolor", 162 | "type": "header-five", 163 | "key": "9p0ic" 164 | }, 165 | { 166 | "entityRanges": [], 167 | "depth": 0, 168 | "data": {}, 169 | "inlineStyleRanges": [], 170 | "text": "Donec vitae orci sed", 171 | "type": "header-six", 172 | "key": "bb6hf" 173 | }, 174 | { 175 | "key": "2galv", 176 | "text": "Proin magna. Donec posuere vulputate arcu", 177 | "type": "ordered-list-item", 178 | "depth": 0, 179 | "inlineStyleRanges": [], 180 | "entityRanges": [], 181 | "data": {} 182 | }, 183 | { 184 | "key": "2grlv", 185 | "text": "Proin magna. Donec posuere vulputate arcu", 186 | "type": "ordered-list-item", 187 | "depth": 1, 188 | "inlineStyleRanges": [], 189 | "entityRanges": [], 190 | "data": {} 191 | }, 192 | { 193 | "key": "2gelv", 194 | "text": "Proin magna. Donec posuere vulputate arcu", 195 | "type": "ordered-list-item", 196 | "depth": 1, 197 | "inlineStyleRanges": [], 198 | "entityRanges": [], 199 | "data": {} 200 | }, 201 | { 202 | "key": "cdsdj", 203 | "text": "Etiam feugiat lorem non metus", 204 | "type": "ordered-list-item", 205 | "depth": 0, 206 | "inlineStyleRanges": [], 207 | "entityRanges": [], 208 | "data": {} 209 | }, 210 | { 211 | "key": "d725p", 212 | "text": " Curabitur at lacus ac velit ornare lobortis", 213 | "type": "ordered-list-item", 214 | "depth": 0, 215 | "inlineStyleRanges": [], 216 | "entityRanges": [], 217 | "data": {} 218 | }, 219 | { 220 | "key": "3grlv", 221 | "text": "Proin magna. Donec posuere vulputate arcu", 222 | "type": "ordered-list-item", 223 | "depth": 1, 224 | "inlineStyleRanges": [], 225 | "entityRanges": [], 226 | "data": {} 227 | }, 228 | { 229 | "key": "3gelv", 230 | "text": "Proin magna. Donec posuere vulputate arcu", 231 | "type": "ordered-list-item", 232 | "depth": 1, 233 | "inlineStyleRanges": [], 234 | "entityRanges": [], 235 | "data": {} 236 | }, 237 | { 238 | "key": "c9mftj", 239 | "text": "Phasellus a est.", 240 | "type": "unordered-list-item", 241 | "depth": 0, 242 | "inlineStyleRanges": [], 243 | "entityRanges": [], 244 | "data": {} 245 | }, 246 | { 247 | "key": "3alra", 248 | "text": "Fusce ac felis sit amet ligula pharetra condimentum", 249 | "type": "unordered-list-item", 250 | "depth": 0, 251 | "inlineStyleRanges": [], 252 | "entityRanges": [], 253 | "data": {} 254 | }, 255 | { 256 | "key": "3hlra", 257 | "text": "Child", 258 | "type": "unordered-list-item", 259 | "depth": 1, 260 | "inlineStyleRanges": [], 261 | "entityRanges": [], 262 | "data": {} 263 | }, 264 | { 265 | "key": "3clra", 266 | "text": "Grantchild", 267 | "type": "unordered-list-item", 268 | "depth": 2, 269 | "inlineStyleRanges": [], 270 | "entityRanges": [], 271 | "data": {} 272 | }, 273 | { 274 | "key": "cniqr", 275 | "text": "Suspendisse faucibus a quam loremipsum ligum purus", 276 | "type": "unordered-list-item", 277 | "depth": 0, 278 | "inlineStyleRanges": [ 279 | { 280 | "offset": 13, 281 | "length": 6, 282 | "style": "ITALIC" 283 | }, 284 | { 285 | "offset": 5, 286 | "length": 30, 287 | "style": "STRIKETHROUGH" 288 | }, 289 | { 290 | "offset": 16, 291 | "length": 9, 292 | "style": "BOLD" 293 | } 294 | ], 295 | "entityRanges": [ 296 | { 297 | "offset": 12, 298 | "length": 8, 299 | "key": 0 300 | } 301 | ], 302 | "data": {} 303 | }, 304 | { 305 | "key": "8cl9h", 306 | "text": "Suspendisse potenti. Fusce a quam. Etiam ut purus mattis mauris sodales aliquam. Morbi vestibulum volutpat enim. Phasellus nec sem in justo pellentesque facilisis.", 307 | "type": "blockquote", 308 | "depth": 0, 309 | "inlineStyleRanges": [], 310 | "entityRanges": [], 311 | "data": {} 312 | }, 313 | { 314 | "entityRanges": [], 315 | "depth": 0, 316 | "data": {}, 317 | "inlineStyleRanges": [], 318 | "text": "'code-block': {\n backgroundColor: '#cecece',\n fontFamily: 'Courier New',\n padding: 16,\n},", 319 | "type": "code-block", 320 | "key": "5aaa7ec3" 321 | } 322 | ], 323 | "entityMap": { 324 | "0": { 325 | "type": "LINK", 326 | "mutability": "MUTABLE", 327 | "data": { 328 | "url": "https://github.com/globocom/react-native-draftjs-render" 329 | } 330 | } 331 | } 332 | } 333 | -------------------------------------------------------------------------------- /src/components/BlockQuote.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | import React from 'react'; 10 | import { 11 | StyleSheet, 12 | View, 13 | } from 'react-native'; 14 | 15 | import DraftJsText from './DraftJsText'; 16 | import type { BlockQuotePropsType } from './types'; 17 | 18 | const styles = StyleSheet.create({ 19 | blockquoteContainer: { 20 | borderLeftColor: '#eee', 21 | borderLeftWidth: 4, 22 | borderStyle: 'solid', 23 | marginTop: 22, 24 | marginBottom: 22, 25 | paddingLeft: 12, 26 | }, 27 | }); 28 | 29 | const BlockQuote = (props: BlockQuotePropsType): any => { 30 | const { customStyles } = props; 31 | const blockquoteCustomStyleContainer = customStyles 32 | ? customStyles.blockquoteContainer 33 | : undefined; 34 | const blockquoteCustomStyleIconBefore = customStyles 35 | ? customStyles.blockquoteIconBefore 36 | : undefined; 37 | const blockquoteCustomStyleIconAfter = customStyles 38 | ? customStyles.blockquoteIconAfter 39 | : undefined; 40 | 41 | return ( 42 | 43 | 44 | 47 | 48 | 49 | ); 50 | }; 51 | 52 | BlockQuote.defaultProps = { 53 | customStyles: undefined, 54 | type: '', 55 | }; 56 | 57 | export default BlockQuote; 58 | -------------------------------------------------------------------------------- /src/components/DraftJsText.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | import React from 'react'; 10 | import { Text } from 'react-native'; 11 | 12 | import loadAttributes from '../loadAttributes'; 13 | 14 | import defaultStyles from './defaultStyles'; 15 | import type { DraftJsTextPropsType } from './types'; 16 | 17 | const DraftJsText = (props: DraftJsTextPropsType): any => { 18 | const { text } = props; 19 | let textElements = text; 20 | 21 | if (textElements) { 22 | textElements = loadAttributes({ 23 | text: props.text, 24 | customStyles: props.customStyles, 25 | inlineStyles: props.inlineStyles, 26 | entityRanges: props.entityRanges, 27 | entityMap: props.entityMap, 28 | navigate: props.navigate, 29 | textProps: props.textProps, 30 | type: props.type, 31 | }); 32 | 33 | const customStyle = props.customStyles ? props.customStyles[props.type] : undefined; 34 | const textAlignStyle = { textAlign: props.data.textAlignment }; 35 | 36 | return ( 37 | 41 | {textElements} 42 | 43 | ); 44 | } 45 | return null; 46 | }; 47 | 48 | DraftJsText.defaultProps = { 49 | text: '', 50 | data: {}, 51 | inlineStyles: [], 52 | navigate: undefined, 53 | }; 54 | 55 | export default DraftJsText; 56 | -------------------------------------------------------------------------------- /src/components/OrderedListItem.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | import React from 'react'; 10 | import { 11 | Text, 12 | View, 13 | StyleSheet, 14 | } from 'react-native'; 15 | 16 | import DraftJsText from './DraftJsText'; 17 | import type { OrderedListItemPropsType } from './types'; 18 | 19 | const styles = StyleSheet.create({ 20 | orderedListItemContainer: { 21 | flex: 1, 22 | flexDirection: 'row', 23 | alignItems: 'center', 24 | }, 25 | orderedListItemNumber: { 26 | fontSize: 12, 27 | fontWeight: 'bold', 28 | alignSelf: 'center', 29 | }, 30 | }); 31 | 32 | const OrderedListItem = (props: OrderedListItemPropsType): any => { 33 | const { 34 | counter, 35 | separator, 36 | customStyles, 37 | depth, 38 | defaultMarginLeft, 39 | } = props; 40 | 41 | const orderedListItemCustomStyleContainer = customStyles && customStyles.orderedListItemContainer; 42 | const orderedListItemCustomStyleNumber = customStyles && customStyles.orderedListItemNumber; 43 | 44 | const marginLeftWithDepth = ( 45 | orderedListItemCustomStyleNumber && orderedListItemCustomStyleNumber.marginLeft) 46 | ? depth * orderedListItemCustomStyleNumber.marginLeft : depth * defaultMarginLeft; 47 | 48 | const marginLeftWithoutDepth = 24; 49 | const marginLeft = depth > 0 ? marginLeftWithDepth : marginLeftWithoutDepth; 50 | 51 | return ( 52 | 53 | 56 | {counter} 57 | {separator} 58 | 59 | 62 | 63 | ); 64 | }; 65 | 66 | OrderedListItem.defaultProps = { 67 | counter: 1, 68 | depth: 0, 69 | separator: '.', 70 | defaultMarginLeft: 8, 71 | }; 72 | 73 | export default OrderedListItem; 74 | -------------------------------------------------------------------------------- /src/components/TextStyled.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | import React from 'react'; 10 | import { 11 | Text, 12 | StyleSheet, 13 | } from 'react-native'; 14 | 15 | import type { TextStyledPropsType } from './types'; 16 | 17 | const styles = StyleSheet.flatten({ 18 | bold: { 19 | fontWeight: 'bold', 20 | }, 21 | italic: { 22 | fontStyle: 'italic', 23 | }, 24 | link: { 25 | textDecorationLine: 'underline', 26 | }, 27 | underline: { 28 | textDecorationLine: 'underline', 29 | }, 30 | strikethrough: { 31 | textDecorationLine: 'line-through', 32 | }, 33 | }); 34 | 35 | const getStyles = (itemType: any, customStyles?: Object): any => { 36 | if (!customStyles) return [styles[itemType]]; 37 | if (typeof itemType === 'string') return [styles[itemType], customStyles[itemType]]; 38 | 39 | const defaultTextStyles = {}; 40 | const customTextStyles = {}; 41 | itemType.forEach((i: string) => { 42 | Object.assign(defaultTextStyles, styles[i]); 43 | if (customStyles) Object.assign(customTextStyles, customStyles[i]); 44 | }); 45 | const newStyles = [defaultTextStyles, customTextStyles]; 46 | return newStyles; 47 | }; 48 | 49 | const TextStyled = (props: TextStyledPropsType): any => { 50 | const { 51 | type, 52 | customStyles, 53 | onPress, 54 | lineHeight, 55 | text, 56 | } = props; 57 | const textStyle = getStyles(type, customStyles); 58 | 59 | if (onPress) { 60 | return {text}; 61 | } 62 | return {text}; 63 | }; 64 | 65 | TextStyled.defaultProps = { 66 | text: '', 67 | onPress: undefined, 68 | }; 69 | 70 | export default TextStyled; 71 | -------------------------------------------------------------------------------- /src/components/UnorderedListItem.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | import React from 'react'; 10 | import { 11 | View, 12 | StyleSheet, 13 | } from 'react-native'; 14 | 15 | import DraftJsText from './DraftJsText'; 16 | import type { UnorderedListItemPropsType } from './types'; 17 | 18 | const styles = StyleSheet.create({ 19 | unorderedListItemContainer: { 20 | flex: 1, 21 | flexDirection: 'row', 22 | alignItems: 'center', 23 | }, 24 | unorderedListItemBullet: { 25 | width: 5, 26 | height: 5, 27 | borderRadius: 5, 28 | marginRight: 8, 29 | alignSelf: 'center', 30 | backgroundColor: 'black', 31 | }, 32 | }); 33 | 34 | const UnorderedListItem = (props: UnorderedListItemPropsType): any => { 35 | const { customStyles, depth, defaultMarginLeft } = props; 36 | const unorderedListItemCustomStyleContainer = customStyles 37 | ? customStyles.unorderedListItemContainer 38 | : undefined; 39 | 40 | const unorderedListItemCustomStyleBullet = customStyles 41 | ? customStyles.unorderedListItemBullet 42 | : undefined; 43 | 44 | let marginLeft = 0; 45 | marginLeft = unorderedListItemCustomStyleBullet && unorderedListItemCustomStyleBullet.marginLeft 46 | ? depth * unorderedListItemCustomStyleBullet.marginLeft 47 | : depth * defaultMarginLeft; 48 | 49 | return ( 50 | 51 | 54 | 57 | 58 | ); 59 | }; 60 | 61 | UnorderedListItem.defaultProps = { 62 | defaultMarginLeft: 8, 63 | depth: 0, 64 | }; 65 | 66 | export default UnorderedListItem; 67 | -------------------------------------------------------------------------------- /src/components/defaultStyles.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | import { 10 | StyleSheet, 11 | Platform, 12 | } from 'react-native'; 13 | 14 | const defaultStyles = (PlatformOS: string): Object => StyleSheet.create({ 15 | paragraph: { 16 | fontSize: 14, 17 | fontWeight: 'normal', 18 | }, 19 | unstyled: { 20 | fontSize: 14, 21 | fontWeight: 'normal', 22 | }, 23 | 'header-one': { 24 | fontSize: 32, 25 | fontWeight: 'bold', 26 | marginTop: 22, 27 | marginBottom: 22, 28 | }, 29 | 'header-two': { 30 | fontSize: 24, 31 | fontWeight: 'bold', 32 | marginTop: 20, 33 | marginBottom: 20, 34 | }, 35 | 'header-three': { 36 | fontSize: 19, 37 | fontWeight: 'bold', 38 | marginTop: 19, 39 | marginBottom: 19, 40 | }, 41 | 'header-four': { 42 | fontSize: 15, 43 | fontWeight: 'bold', 44 | marginTop: 21, 45 | marginBottom: 21, 46 | }, 47 | 'header-five': { 48 | fontSize: 13, 49 | fontWeight: 'bold', 50 | marginTop: 22, 51 | marginBottom: 22, 52 | }, 53 | 'header-six': { 54 | fontSize: 11, 55 | fontWeight: 'bold', 56 | marginTop: 25, 57 | marginBottom: 25, 58 | }, 59 | 'unordered-list-item': { 60 | fontSize: 14, 61 | fontWeight: 'normal', 62 | }, 63 | 'ordered-list-item': { 64 | fontSize: 14, 65 | fontWeight: 'normal', 66 | }, 67 | 'code-block': { 68 | backgroundColor: '#cecece', 69 | fontFamily: PlatformOS === 'android' ? 'monospace' : 'Courier New', 70 | padding: 16, 71 | }, 72 | blockquote: { 73 | fontSize: 14, 74 | fontWeight: 'normal', 75 | fontStyle: 'italic', 76 | marginLeft: 16, 77 | }, 78 | }); 79 | 80 | export { defaultStyles as defaultStylesForTest }; 81 | export default defaultStyles(Platform.OS); 82 | -------------------------------------------------------------------------------- /src/components/types.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | export type BlockQuotePropsType = { 10 | type: string, 11 | text: string, 12 | data: Object, 13 | customStyles?: Object, 14 | inlineStyles: Array, 15 | entityRanges: Array, 16 | entityMap: ?Object, 17 | textProps: ?Object, 18 | }; 19 | 20 | export type DraftJsTextPropsType = { 21 | type: string, 22 | text: string, 23 | data: Object, 24 | customStyles?: Object, 25 | inlineStyles: Array, 26 | entityRanges: Array, 27 | entityMap: ?Object, 28 | navigate?: Function, 29 | textProps: ?Object, 30 | }; 31 | 32 | export type OrderedListItemPropsType = { 33 | type: string, 34 | text: string, 35 | data: Object, 36 | customStyles?: Object, 37 | inlineStyles: Array, 38 | entityRanges: Array, 39 | entityMap: ?Object, 40 | counter: number, 41 | separator?: string, 42 | depth: number, 43 | defaultMarginLeft: number, 44 | textProps: ?Object, 45 | }; 46 | 47 | export type UnorderedListItemPropsType = { 48 | type: string, 49 | text: string, 50 | data: Object, 51 | customStyles?: Object, 52 | inlineStyles: Array, 53 | entityRanges: Array, 54 | entityMap: ?Object, 55 | depth: number, 56 | defaultMarginLeft: number, 57 | textProps: ?Object, 58 | }; 59 | 60 | export type TextStyledPropsType = { 61 | type: string, 62 | text: string, 63 | customStyles?: Object, 64 | onPress?: Function, 65 | lineHeight: Object, 66 | }; 67 | -------------------------------------------------------------------------------- /src/flatAttributesList.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | const sortInteger = (a: number, b: number): number => a - b; 10 | const isLink = (element: Object): boolean => Object.prototype.hasOwnProperty.call(element, 'key'); 11 | 12 | const convertStylesIntoNumbers = (styles: Array): Array => { 13 | const numbers = []; 14 | styles.forEach((style: Object) => { 15 | numbers.push(style.offset); 16 | numbers.push(style.offset + style.length); 17 | }); 18 | return numbers; 19 | }; 20 | 21 | const createArrayWithSegments = (numbersList: Array): Array> => { 22 | const segmentList = []; 23 | const numbersListLength = numbersList.length; 24 | for (let i = 0; i < numbersListLength - 1; i += 1) { 25 | segmentList.push([numbersList[i], numbersList[i + 1] - numbersList[i]]); 26 | } 27 | return segmentList; 28 | }; 29 | 30 | const addTypeToSegments = ( 31 | segments: Array>, 32 | originalStyles: Array, 33 | ): Array => { 34 | const objectList = []; 35 | segments.forEach((segment: Array) => { 36 | const types = []; 37 | originalStyles.forEach((style: Object) => { 38 | const length = segment[0] + segment[1]; 39 | if (length > style.offset && length <= style.offset + style.length) { 40 | if (isLink(style)) { 41 | types.push('link'); 42 | segment.push(style.key); 43 | } else { 44 | types.push(style.style); 45 | } 46 | } 47 | }); 48 | if (types.length) { 49 | const attr = Object.assign({}, { offset: segment[0], length: segment[1] }); 50 | const t = types.length === 1 ? types[0] : types; 51 | Object.assign(attr, { style: t }); 52 | if (segment.length === 3) Object.assign(attr, { key: segment[2] }); 53 | objectList.push(attr); 54 | } 55 | }); 56 | return objectList; 57 | }; 58 | 59 | const isOverlap = (styles: Array): any => { 60 | let found; 61 | for (let i = 0; i < styles.length - 1; i += 1) { 62 | found = styles 63 | .find((item: Object): boolean => ( 64 | item.offset >= styles[i].offset && item.offset <= styles[i].offset + styles[i].length)); 65 | if (found) break; 66 | } 67 | return found; 68 | }; 69 | 70 | const checkSingleLinkElement = (item: Object) => { 71 | if (isLink(item)) { 72 | Object.assign(item, { style: 'link' }); 73 | } 74 | }; 75 | 76 | const flatAttributesList = (attrsList: Array): Array => { 77 | if (attrsList.length === 1 || !isOverlap(attrsList)) { 78 | checkSingleLinkElement(attrsList[0]); 79 | return attrsList; 80 | } 81 | const numbersList = convertStylesIntoNumbers(attrsList); 82 | const sortedNumbersList = numbersList.sort(sortInteger); 83 | const uniqueSortedNumbersList = Array.from(new Set(sortedNumbersList)); 84 | const segments = createArrayWithSegments(uniqueSortedNumbersList); 85 | const finalObject = addTypeToSegments(segments, attrsList); 86 | return finalObject; 87 | }; 88 | 89 | export default flatAttributesList; 90 | -------------------------------------------------------------------------------- /src/getBlocks.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | import React from 'react'; 10 | import { View } from 'react-native'; 11 | 12 | import BlockQuote from './components/BlockQuote'; 13 | import DraftJsText from './components/DraftJsText'; 14 | import UnorderedListItem from './components/UnorderedListItem'; 15 | import OrderedListItem from './components/OrderedListItem'; 16 | import generateKey from './utils/generateKey'; 17 | 18 | type ParamsType = { 19 | contentState: { 20 | blocks: ?Array<*>, 21 | entityMap: Object, 22 | }, 23 | customStyles: Object, 24 | atomicHandler: Function, 25 | navigate?: Function, 26 | orderedListSeparator?: string, 27 | customBlockHandler?: (Object, ParamsType) => any, 28 | depthMargin?: number, 29 | textProps: ?Object, 30 | }; 31 | 32 | export const ViewAfterList = (props: Object): React$Element<*> => ( 33 | 34 | ); 35 | 36 | const getBlocks = (params: ParamsType): ?Array> => { 37 | const { 38 | contentState, 39 | customStyles, 40 | navigate, 41 | orderedListSeparator, 42 | customBlockHandler, 43 | depthMargin, 44 | atomicHandler, 45 | } = params; 46 | 47 | const textProps = params.textProps || {}; 48 | 49 | if (!contentState.blocks) { 50 | return null; 51 | } 52 | 53 | const counters = { 54 | 'unordered-list-item': { 55 | count: 0, 56 | type: 'unordered-list-item', 57 | childCounters: [], 58 | }, 59 | 'ordered-list-item': { 60 | count: 0, 61 | type: 'ordered-list-item', 62 | childCounters: [], 63 | }, 64 | }; 65 | 66 | const checkCounter = (counter: Object): ?React$Element<*> => { 67 | const myCounter = counter; 68 | 69 | // list types 70 | if (myCounter.count >= 0) { 71 | if (myCounter.count > 0) { 72 | myCounter.count = 0; 73 | return ( 74 | 78 | ); 79 | } 80 | return null; 81 | } 82 | 83 | // non list types 84 | if (myCounter['unordered-list-item'].count > 0 || myCounter['ordered-list-item'].count > 0) { 85 | myCounter['unordered-list-item'].count = 0; 86 | myCounter['ordered-list-item'].count = 0; 87 | return ( 88 | 92 | ); 93 | } 94 | 95 | return null; 96 | }; 97 | 98 | return contentState.blocks 99 | .map((item: Object): React$Element<*> => { 100 | const itemData = { 101 | key: item.key, 102 | text: item.text, 103 | type: item.type, 104 | data: item.data, 105 | inlineStyles: item.inlineStyleRanges, 106 | entityRanges: item.entityRanges, 107 | depth: item.depth, 108 | }; 109 | 110 | switch (item.type) { 111 | case 'unstyled': 112 | case 'paragraph': 113 | case 'header-one': 114 | case 'header-two': 115 | case 'header-three': 116 | case 'header-four': 117 | case 'header-five': 118 | case 'header-six': 119 | case 'code-block': { 120 | const viewBefore = checkCounter(counters); 121 | return ( 122 | 123 | {viewBefore} 124 | 131 | 132 | ); 133 | } 134 | 135 | case 'atomic': { 136 | if (atomicHandler) { 137 | const viewBefore = checkCounter(counters); 138 | const atomic = atomicHandler(item, contentState.entityMap); 139 | if (viewBefore) { 140 | return ( 141 | 142 | {viewBefore} 143 | {atomic} 144 | 145 | ); 146 | } 147 | return atomic; 148 | } 149 | return item; 150 | } 151 | 152 | case 'blockquote': { 153 | const viewBefore = checkCounter(counters); 154 | return ( 155 | 156 | {viewBefore} 157 |
164 | 165 | ); 166 | } 167 | 168 | case 'unordered-list-item': { 169 | counters[item.type].count += 1; 170 | const viewBefore = checkCounter(counters['ordered-list-item']); 171 | return ( 172 | 173 | {viewBefore} 174 | 182 | 183 | ); 184 | } 185 | 186 | case 'ordered-list-item': { 187 | const { type } = item; 188 | const parentIndex = counters[type].count; 189 | let number = 0; 190 | 191 | // when new ordered list reset childCounters 192 | if (parentIndex === 0) { 193 | counters[type].childCounters = []; 194 | } 195 | 196 | if (itemData.depth !== undefined && itemData.depth >= 1) { 197 | if (counters[type].childCounters[parentIndex] === undefined) { 198 | counters[type].childCounters[parentIndex] = 0; 199 | } 200 | counters[type].childCounters[parentIndex] += 1; 201 | number = counters[type].childCounters[parentIndex]; 202 | } else { 203 | counters[type].count += 1; 204 | number = counters[type].count; 205 | } 206 | 207 | const viewBefore = checkCounter(counters['unordered-list-item']); 208 | return ( 209 | 210 | {viewBefore} 211 | 221 | 222 | ); 223 | } 224 | 225 | default: { 226 | const viewBefore = checkCounter(counters); 227 | return customBlockHandler ? customBlockHandler(item, params) : ( 228 | 229 | {viewBefore} 230 | 231 | ); 232 | } 233 | } 234 | }); 235 | }; 236 | 237 | export default getBlocks; 238 | -------------------------------------------------------------------------------- /src/helpers/getItemType.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | const getItemType = (item: Object): string => { 10 | if (item.style) { 11 | if (Array.isArray(item.style)) { 12 | return item.style.map((i: string): string => i.toLowerCase()); 13 | } 14 | return item.style.toLowerCase(); 15 | } 16 | return ''; 17 | }; 18 | 19 | export default getItemType; 20 | -------------------------------------------------------------------------------- /src/helpers/isEmptyObject.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | const isEmptyObject = (obj: Object): boolean => Object.keys(obj).length === 0; 10 | 11 | export default isEmptyObject; 12 | -------------------------------------------------------------------------------- /src/loadAttributes.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | // @flow 8 | 9 | import { substring, length } from 'stringz'; 10 | import React from 'react'; 11 | import { 12 | Text, 13 | Linking, 14 | } from 'react-native'; 15 | 16 | import TextStyled from './components/TextStyled'; 17 | import defaultStyles from './components/defaultStyles'; 18 | import generateKey from './utils/generateKey'; 19 | import flatAttributesList from './flatAttributesList'; 20 | import getItemType from './helpers/getItemType'; 21 | import isEmptyObject from './helpers/isEmptyObject'; 22 | 23 | export const getItemOnPress = (item: Object, entityMap: ?Object, navigate: Function) => { 24 | if (item.key !== undefined && entityMap && !isEmptyObject(entityMap)) { 25 | // $$FlowFixMe entityMap is valid here 26 | return () => { navigate(entityMap[item.key].data.url); }; 27 | } 28 | return undefined; 29 | }; 30 | 31 | type ParamsType = { 32 | text: string, 33 | type: string, 34 | customStyles?: Object, 35 | inlineStyles: Array, 36 | entityRanges: Array, 37 | entityMap: ?Object, 38 | navigate?: Function, 39 | textProps: ?Object, 40 | }; 41 | 42 | const loadAttributes = (params: ParamsType): any => { 43 | const { 44 | text, 45 | customStyles, 46 | inlineStyles, 47 | entityRanges, 48 | entityMap, 49 | navigate, 50 | textProps, 51 | type, 52 | } = params; 53 | 54 | const defaultNavigationFn = (url: string) => { Linking.openURL(url); }; 55 | const navigateFunction = navigate || defaultNavigationFn; 56 | const elementList = []; 57 | let attributes = inlineStyles ? inlineStyles.concat(entityRanges) : entityRanges; 58 | attributes = attributes.sort((a: Object, b: Object): number => a.offset - b.offset); 59 | 60 | if (attributes.length) { 61 | const attrs = flatAttributesList(attributes); 62 | 63 | const defaultLineHeight = defaultStyles[type] && defaultStyles[type].lineHeight; 64 | const customLineHeight = customStyles && customStyles[type] && customStyles[type].lineHeight; 65 | const lineHeight = { lineHeight: customLineHeight || defaultLineHeight }; 66 | 67 | if (attrs[0].offset > 0) { 68 | const element = ( 69 | 70 | {substring(text, 0, attrs[0].offset)} 71 | 72 | ); 73 | elementList.push(element); 74 | } 75 | 76 | attrs.forEach((item: Object, index: number) => { 77 | if (index > 0) { 78 | const previousItem = attrs[index - 1]; 79 | const offset = previousItem.offset + previousItem.length; 80 | const subText = substring(text, offset, item.offset); 81 | 82 | if (subText.length) { 83 | elementList.push({subText}); 84 | } 85 | } 86 | 87 | const itemType = getItemType(item); 88 | const itemData = Object.assign({}, { 89 | key: generateKey(), 90 | type: itemType, 91 | text: substring(text, item.offset, item.offset + item.length), 92 | customStyles, 93 | textProps, 94 | lineHeight, 95 | }); 96 | 97 | const itemOnPress = getItemOnPress(item, entityMap, navigateFunction); 98 | if (itemOnPress !== undefined) Object.assign(itemData, { onPress: itemOnPress }); 99 | 100 | elementList.push(( 101 | 102 | )); 103 | }); 104 | 105 | const lastItem = attrs[attrs.length - 1]; 106 | const offset = lastItem.offset + lastItem.length; 107 | const subText = substring(text, offset, length(text)); 108 | 109 | if (subText.length) { 110 | elementList.push({subText}); 111 | } 112 | } else { 113 | elementList.push(text); 114 | } 115 | 116 | return elementList; 117 | }; 118 | 119 | export default loadAttributes; 120 | -------------------------------------------------------------------------------- /src/utils/generateKey.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Globo.com (https://github.com/globocom) 3 | * 4 | * License: MIT 5 | */ 6 | 7 | export default function generateKey(): number { 8 | function s4() { 9 | return Math.floor((1 + Math.random()) * 0x10000) 10 | .toString(16) 11 | .substring(1); 12 | } 13 | return `${s4()}${s4()}-${s4()}-${s4()}${s4()}-${s4()}${s4()}-${s4()}${s4()}${s4()}`; 14 | } 15 | --------------------------------------------------------------------------------