Suppress spoiler for easier reading

As spoiler is default expanded now in thread
This commit is contained in:
xmflsct 2023-01-29 19:27:15 +01:00
parent aba239188f
commit 83cd5d4eb0
6 changed files with 24 additions and 8 deletions

View File

@ -6,7 +6,7 @@ import { StyleConstants } from '@utils/styles/constants'
import { adaptiveScale } from '@utils/styles/scaling' import { adaptiveScale } from '@utils/styles/scaling'
import { useTheme } from '@utils/styles/ThemeManager' import { useTheme } from '@utils/styles/ThemeManager'
import React from 'react' import React from 'react'
import { Platform, TextStyle } from 'react-native' import { ColorValue, Platform, TextStyle } from 'react-native'
import FastImage from 'react-native-fast-image' import FastImage from 'react-native-fast-image'
const regexEmoji = new RegExp(/(:[A-Za-z0-9_]+:)/) const regexEmoji = new RegExp(/(:[A-Za-z0-9_]+:)/)
@ -15,6 +15,7 @@ export interface Props {
content?: string content?: string
emojis?: Mastodon.Emoji[] emojis?: Mastodon.Emoji[]
size?: 'S' | 'M' | 'L' size?: 'S' | 'M' | 'L'
color?: ColorValue
adaptiveSize?: boolean adaptiveSize?: boolean
fontBold?: boolean fontBold?: boolean
style?: TextStyle style?: TextStyle
@ -24,6 +25,7 @@ const ParseEmojis: React.FC<Props> = ({
content, content,
emojis, emojis,
size = 'M', size = 'M',
color,
adaptiveSize = false, adaptiveSize = false,
fontBold = false, fontBold = false,
style style
@ -42,13 +44,13 @@ const ParseEmojis: React.FC<Props> = ({
adaptiveSize ? adaptiveFontsize : 0 adaptiveSize ? adaptiveFontsize : 0
) )
const { colors, theme } = useTheme() const { colors } = useTheme()
return ( return (
<CustomText <CustomText
style={[ style={[
{ {
color: colors.primaryDefault, color: color || colors.primaryDefault,
fontSize: adaptedFontsize, fontSize: adaptedFontsize,
lineHeight: adaptedLineheight lineHeight: adaptedLineheight
}, },

View File

@ -16,11 +16,12 @@ import { ElementType, parseDocument } from 'htmlparser2'
import i18next from 'i18next' import i18next from 'i18next'
import React, { useContext, useRef, useState } from 'react' import React, { useContext, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Platform, Pressable, Text, View } from 'react-native' import { ColorValue, Platform, Pressable, Text, View } from 'react-native'
export interface Props { export interface Props {
content: string content: string
size?: 'S' | 'M' | 'L' size?: 'S' | 'M' | 'L'
color?: ColorValue
adaptiveSize?: boolean adaptiveSize?: boolean
showFullLink?: boolean showFullLink?: boolean
numberOfLines?: number numberOfLines?: number
@ -34,6 +35,7 @@ export interface Props {
const ParseHTML: React.FC<Props> = ({ const ParseHTML: React.FC<Props> = ({
content, content,
size = 'M', size = 'M',
color,
adaptiveSize = false, adaptiveSize = false,
showFullLink = false, showFullLink = false,
numberOfLines = 10, numberOfLines = 10,
@ -58,6 +60,7 @@ const ParseHTML: React.FC<Props> = ({
const navigation = useNavigation<StackNavigationProp<TabLocalStackParamList>>() const navigation = useNavigation<StackNavigationProp<TabLocalStackParamList>>()
const { params } = useRoute() const { params } = useRoute()
const { colors } = useTheme() const { colors } = useTheme()
const colorPrimary = color || colors.primaryDefault
const { t } = useTranslation('componentParse') const { t } = useTranslation('componentParse')
if (!expandHint) { if (!expandHint) {
expandHint = t('HTML.defaultHint') expandHint = t('HTML.defaultHint')
@ -111,6 +114,7 @@ const ParseHTML: React.FC<Props> = ({
content={content} content={content}
emojis={status?.emojis || emojis} emojis={status?.emojis || emojis}
size={size} size={size}
color={colorPrimary}
adaptiveSize={adaptiveSize} adaptiveSize={adaptiveSize}
/> />
) )
@ -181,7 +185,7 @@ const ParseHTML: React.FC<Props> = ({
return ( return (
<Text <Text
key={index} key={index}
style={{ color: matchedMention ? colors.blue : colors.primaryDefault }} style={{ color: matchedMention ? colors.blue : colorPrimary }}
onPress={() => onPress={() =>
matchedMention && matchedMention &&
!disableDetails && !disableDetails &&

View File

@ -33,6 +33,7 @@ export interface Props {
item: Mastodon.Status & { _pinned?: boolean } // For account page, internal property item: Mastodon.Status & { _pinned?: boolean } // For account page, internal property
queryKey?: QueryKeyTimeline queryKey?: QueryKeyTimeline
highlighted?: boolean highlighted?: boolean
suppressSpoiler?: boolean // Same content as the main thread, can be dimmed
disableDetails?: boolean disableDetails?: boolean
disableOnPress?: boolean disableOnPress?: boolean
isConversation?: boolean isConversation?: boolean
@ -44,6 +45,7 @@ const TimelineDefault: React.FC<Props> = ({
item, item,
queryKey, queryKey,
highlighted = false, highlighted = false,
suppressSpoiler = false,
disableDetails = false, disableDetails = false,
disableOnPress = false, disableOnPress = false,
isConversation = false, isConversation = false,
@ -170,6 +172,7 @@ const TimelineDefault: React.FC<Props> = ({
detectedLanguage, detectedLanguage,
excludeMentions, excludeMentions,
highlighted, highlighted,
suppressSpoiler,
inThread: queryKey?.[1].page === 'Toot', inThread: queryKey?.[1].page === 'Toot',
disableDetails, disableDetails,
disableOnPress, disableOnPress,

View File

@ -14,7 +14,7 @@ export interface Props {
} }
const TimelineContent: React.FC<Props> = ({ notificationOwnToot = false, setSpoilerExpanded }) => { const TimelineContent: React.FC<Props> = ({ notificationOwnToot = false, setSpoilerExpanded }) => {
const { status, highlighted, inThread } = useContext(StatusContext) const { status, highlighted, suppressSpoiler, inThread } = useContext(StatusContext)
if (!status || typeof status.content !== 'string' || !status.content.length) return null if (!status || typeof status.content !== 'string' || !status.content.length) return null
const { colors } = useTheme() const { colors } = useTheme()
@ -35,6 +35,7 @@ const TimelineContent: React.FC<Props> = ({ notificationOwnToot = false, setSpoi
size={highlighted ? 'L' : 'M'} size={highlighted ? 'L' : 'M'}
adaptiveSize adaptiveSize
numberOfLines={999} numberOfLines={999}
color={suppressSpoiler ? colors.disabled : undefined}
/> />
{inThread ? ( {inThread ? (
<CustomText <CustomText

View File

@ -15,6 +15,7 @@ type StatusContextType = {
excludeMentions?: React.MutableRefObject<Mastodon.Mention[]> excludeMentions?: React.MutableRefObject<Mastodon.Mention[]>
highlighted?: boolean highlighted?: boolean
suppressSpoiler?: boolean
inThread?: boolean inThread?: boolean
disableDetails?: boolean disableDetails?: boolean
disableOnPress?: boolean disableOnPress?: boolean

View File

@ -346,8 +346,13 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
<TimelineDefault <TimelineDefault
item={item} item={item}
queryKey={item._remote ? queryKey.remote : queryKey.local} queryKey={item._remote ? queryKey.remote : queryKey.local}
highlighted={toot.id === item.id || item.id === 'cached'} highlighted={toot.id === item.id}
isConversation={toot.id !== item.id && item.id !== 'cached'} suppressSpoiler={
toot.id !== item.id &&
!!toot.spoiler_text?.length &&
toot.spoiler_text === item.spoiler_text
}
isConversation={toot.id !== item.id}
noBackground noBackground
/> />
{/* <CustomText {/* <CustomText