Repository navigation
fix inline code blocks for native platforms #2307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Luke9389
merged 10 commits into
Expensify:main
from
parasharrajat:parasharrajat/quotedText
Apr 20, 2021
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
70179c7
fix: inline code blocks for native platforms
parasharrajat 71f68e6
fix vertical alignment of text
parasharrajat 92cebd7
styles inline code
parasharrajat ed7a139
gap in rows
parasharrajat 441ffd7
Merge branch 'master' of github.com:Expensify/Expensify.cash into par…
parasharrajat 7d88395
fix: styles
parasharrajat f764793
fix: block styles
parasharrajat f5290a1
fix: cross platform styling
parasharrajat 80f3219
chg: linting
parasharrajat 92ddc5a
Merge branch 'main' of github.com:Expensify/Expensify.cash into paras…
parasharrajat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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, | ||
| }; | ||
|
parasharrajat marked this conversation as resolved.
Resolved
|
||
|
|
||
| const defaultProps = { | ||
| textStyle: {}, | ||
| wordStyle: {}, | ||
| firstWordStyle: {}, | ||
| lastWordStyle: {}, | ||
| }; | ||
|
parasharrajat marked this conversation as resolved.
Resolved
|
||
|
|
||
| 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> | ||
| ))} | ||
| </> | ||
| ); | ||
| }; | ||
|
parasharrajat marked this conversation as resolved.
Resolved
|
||
|
|
||
| WrappedText.propTypes = propTypes; | ||
| WrappedText.defaultProps = defaultProps; | ||
| WrappedText.displayName = 'WrappedText'; | ||
|
|
||
| export default WrappedText; | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -1311,6 +1311,39 @@ const styles = { | |
| scrollbarWidth: 'none', | ||
| }, | ||
|
|
||
| codeWordWrapper: { | ||
| height: 10, | ||
| }, | ||
|
|
||
| codeWordStyle: { | ||
| borderLeftWidth: 0, | ||
| borderRightWidth: 0, | ||
| borderTopLeftRadius: 0, | ||
| borderBottomLeftRadius: 0, | ||
| borderTopRightRadius: 0, | ||
| borderBottomRightRadius: 0, | ||
| flexBasis: 'auto', | ||
| paddingLeft: 0, | ||
| paddingRight: 0, | ||
| justifyContent: 'center', | ||
| marginVertical: -2, | ||
| top: -1, | ||
| }, | ||
|
|
||
| codeFirstWordStyle: { | ||
| borderLeftWidth: 1, | ||
| borderTopLeftRadius: 4, | ||
| borderBottomLeftRadius: 4, | ||
| paddingLeft: 5, | ||
| }, | ||
|
|
||
| codeLastWordStyle: { | ||
| borderRightWidth: 1, | ||
| borderTopRightRadius: 4, | ||
| borderBottomRightRadius: 4, | ||
| paddingRight: 5, | ||
| }, | ||
|
|
||
| fullScreenLoading: { | ||
| backgroundColor: themeColors.componentBG, | ||
| opacity: 0.8, | ||
|
|
@@ -1331,8 +1364,6 @@ const styles = { | |
| const baseCodeTagStyles = { | ||
| borderWidth: 1, | ||
| borderRadius: 5, | ||
| marginTop: 4, | ||
| marginBottom: 4, | ||
| borderColor: themeColors.border, | ||
| backgroundColor: themeColors.textBackground, | ||
| }; | ||
|
|
@@ -1389,9 +1420,9 @@ const webViewStyles = { | |
| ...baseCodeTagStyles, | ||
| paddingLeft: 5, | ||
| paddingRight: 5, | ||
| paddingBottom: 2, | ||
| alignSelf: 'flex-start', | ||
| fontFamily: fontFamily.MONOSPACE, | ||
| lineHeight: 18, | ||
| fontSize: 13, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The inline code block font size was being inherited. But after explicitly setting it to 13px, it's always rendered at 13px even if the parent is a |
||
| }, | ||
|
|
||
| img: { | ||
|
|
@@ -1404,6 +1435,7 @@ const webViewStyles = { | |
| baseFontStyle: { | ||
| color: themeColors.text, | ||
| fontSize: variables.fontSizeNormal, | ||
| lineHeight: variables.fontSizeNormalHeight, | ||
| fontFamily: fontFamily.GTA, | ||
| }, | ||
| }; | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.