-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: pressable card title #4191
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
Open
mtch99
wants to merge
6
commits into
callstack:main
Choose a base branch
from
mtch99:feat/pressable-card-title
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c18df42
feat: pressable card tite
mtch99 68e9012
fix: pressable zone takes minmal space
mtch99 d465832
refactor: titles style
mtch99 246d56d
fix: changed CardTitle container to Pressable
mtch99 30616c1
refactor: removed duplicated code in title render
mtch99 2957715
refactor: standardized coding style for render
mtch99 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 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ import { | |
StyleProp, | ||
StyleSheet, | ||
TextStyle, | ||
TouchableOpacity, | ||
View, | ||
ViewStyle, | ||
} from 'react-native'; | ||
|
@@ -109,6 +110,11 @@ export type Props = React.ComponentPropsWithRef<typeof View> & { | |
* @optional | ||
*/ | ||
theme?: ThemeProp; | ||
/** | ||
* @optional | ||
* Makes the card title pressable | ||
*/ | ||
onPressTitle?: () => void; | ||
}; | ||
|
||
const LEFT_SIZE = 40; | ||
|
@@ -150,6 +156,7 @@ const CardTitle = ({ | |
rightStyle, | ||
style, | ||
theme: themeOverrides, | ||
onPressTitle, | ||
}: Props) => { | ||
const theme = useInternalTheme(themeOverrides); | ||
const TitleComponent = theme.isV3 ? Text : Title; | ||
|
@@ -169,7 +176,18 @@ const CardTitle = ({ | |
) : null} | ||
|
||
<View style={[styles.titles]}> | ||
{title && ( | ||
{title && onPressTitle ? ( | ||
<TouchableOpacity onPress={onPressTitle} style={[styles.title]}> | ||
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. Use |
||
<TitleComponent | ||
style={[{ marginBottom }, titleStyle]} | ||
numberOfLines={titleNumberOfLines} | ||
variant={titleVariant} | ||
maxFontSizeMultiplier={titleMaxFontSizeMultiplier} | ||
> | ||
{title} | ||
</TitleComponent> | ||
</TouchableOpacity> | ||
) : ( | ||
<TitleComponent | ||
style={[styles.title, { marginBottom }, titleStyle]} | ||
numberOfLines={titleNumberOfLines} | ||
|
@@ -219,6 +237,7 @@ const styles = StyleSheet.create({ | |
}, | ||
|
||
title: { | ||
alignSelf: 'flex-start', | ||
minHeight: 30, | ||
paddingRight: 16, | ||
}, | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid code repetition and move the title outside the render then used wrapped in pressable and without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After moving the Title component from the render, I did the same for subtitle to keep preserve coding style consistency, also had to rename some variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the changes okay? Or Is there something I have to correct? @lukewalczak