-
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 #2527 from parasharrajat/parasharrajat/quotedText
fix inline code blocks
- Loading branch information
Showing
9 changed files
with
162 additions
and
36 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 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,76 @@ | ||
import _ from 'underscore'; | ||
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 => _.without(row.split(/(\s)/), '')); | ||
} | ||
|
||
const propTypes = { | ||
// Required text | ||
children: PropTypes.string.isRequired, | ||
|
||
// Style to be applied to Text | ||
textStyles: PropTypes.arrayOf(PropTypes.object), | ||
|
||
// Style for each word(Token) in the text, | ||
// remember that token also includes whitespaces among words | ||
wordStyles: PropTypes.arrayOf(PropTypes.object), | ||
}; | ||
|
||
const defaultProps = { | ||
textStyles: [], | ||
wordStyles: [], | ||
}; | ||
|
||
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.wordStyles, | ||
colIndex === 0 && styles.codeFirstWordStyle, | ||
colIndex === rowText.length - 1 && styles.codeLastWordStyle, | ||
]} | ||
> | ||
<Text style={props.textStyles}>{colText}</Text> | ||
</View> | ||
</View> | ||
))} | ||
</Fragment> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
WrappedText.propTypes = propTypes; | ||
WrappedText.defaultProps = defaultProps; | ||
WrappedText.displayName = 'WrappedText'; | ||
|
||
export default WrappedText; |
This file was deleted.
Oops, something went wrong.
21 changes: 11 additions & 10 deletions
21
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,14 @@ | ||
const codeWordWrapper = { | ||
height: 10, | ||
}; | ||
|
||
const codeWordStyle = { | ||
top: -1, | ||
marginVertical: -2, | ||
}; | ||
|
||
const codeTextStyle = { | ||
lineHeight: 18, | ||
}; | ||
|
||
export default {codeWordWrapper, codeWordStyle, codeTextStyle}; |
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,16 @@ | ||
const codeWordWrapper = { | ||
height: 18, | ||
justifyContent: 'center', | ||
marginTop: 2, | ||
}; | ||
|
||
const codeWordStyle = { | ||
height: 16, | ||
top: 4, | ||
}; | ||
|
||
const codeTextStyle = { | ||
lineHeight: 15, | ||
}; | ||
|
||
export default {codeWordWrapper, codeWordStyle, codeTextStyle}; |
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,5 @@ | ||
// We do not need these on Web/Desktop as their implementation defer from Native devices so just noop them | ||
const codeWordWrapper = {}; | ||
const codeWordStyle = {}; | ||
const codeTextStyle = {}; | ||
export default {codeWordWrapper, codeWordStyle, codeTextStyle}; |
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