-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2307 from parasharrajat/parasharrajat/quotedText
fix inline code blocks for native platforms
- Loading branch information
Showing
6 changed files
with
139 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
19 changes: 11 additions & 8 deletions
19
src/components/InlineCodeBlock/index.ios.js → ...omponents/InlineCodeBlock/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, {Fragment} from 'react'; | ||
import {Text, View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '../../styles/styles'; | ||
|
||
/** | ||
* Breaks the text into matrix | ||
* for eg: My Name is Rajat | ||
* [ | ||
* [My,'',Name,'','',is,'',Rajat], | ||
* ] | ||
* | ||
* @param {String} text | ||
* @returns {Array<String[]>} | ||
*/ | ||
function getTextMatrix(text) { | ||
return text.split('\n').map(row => row.split(/(\s)/)); | ||
} | ||
|
||
const propTypes = { | ||
// Required text | ||
children: PropTypes.string.isRequired, | ||
|
||
// Style to be applied to Text | ||
// eslint-disable-next-line react/forbid-prop-types | ||
textStyle: PropTypes.object, | ||
|
||
// Style for each word(Token) in the text, | ||
// remember that token also includes the following spaces before next word break | ||
// eslint-disable-next-line react/forbid-prop-types | ||
wordStyle: PropTypes.object, | ||
|
||
// Style for first word | ||
// eslint-disable-next-line react/forbid-prop-types | ||
firstWordStyle: PropTypes.object, | ||
|
||
// Style for last word | ||
// eslint-disable-next-line react/forbid-prop-types | ||
lastWordStyle: PropTypes.object, | ||
}; | ||
|
||
const defaultProps = { | ||
textStyle: {}, | ||
wordStyle: {}, | ||
firstWordStyle: {}, | ||
lastWordStyle: {}, | ||
}; | ||
|
||
const WrappedText = (props) => { | ||
const textMatrix = getTextMatrix(props.children); | ||
return ( | ||
<> | ||
{textMatrix.map((rowText, rowIndex) => ( | ||
<Fragment | ||
// eslint-disable-next-line react/no-array-index-key | ||
key={`${rowText}-${rowIndex}`} | ||
> | ||
{rowText.map((colText, colIndex) => ( | ||
|
||
// Outer View is important to vertically center the Text | ||
<View | ||
// eslint-disable-next-line react/no-array-index-key | ||
key={`${colText}-${colIndex}`} | ||
style={styles.codeWordWrapper} | ||
> | ||
<View | ||
style={[ | ||
props.wordStyle, | ||
colIndex === 0 && props.firstWordStyle, | ||
colIndex === rowText.length - 1 && props.lastWordStyle, | ||
]} | ||
> | ||
<Text style={props.textStyle}>{colText}</Text> | ||
</View> | ||
</View> | ||
))} | ||
</Fragment> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
WrappedText.propTypes = propTypes; | ||
WrappedText.defaultProps = defaultProps; | ||
WrappedText.displayName = 'WrappedText'; | ||
|
||
export default WrappedText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters