Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32210079
D5541.1765129320.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D5541.1765129320.diff
View Options
diff --git a/native/chat/inner-text-message.react.js b/native/chat/inner-text-message.react.js
--- a/native/chat/inner-text-message.react.js
+++ b/native/chat/inner-text-message.react.js
@@ -13,6 +13,7 @@
import { useColors, colors } from '../themes/colors';
import type { ChatTextMessageInfoItemWithHeight } from '../types/chat-types';
import { useComposedMessageMaxWidth } from './composed-message-width';
+import { MessageContext } from './message-context.react';
import { MessageListContext } from './message-list-types';
import {
allCorners,
@@ -101,6 +102,10 @@
return [styles.text, textStyle];
}, [darkColor]);
+ const contextValue = {
+ messageID: item.messageInfo.id ?? '',
+ };
+
const message = (
<TouchableWithoutFeedback>
<View>
@@ -111,9 +116,11 @@
style={[styles.message, cornerStyle]}
animatedStyle={messageStyle}
>
- <Markdown style={markdownStyles} rules={rules}>
- {text}
- </Markdown>
+ <MessageContext.Provider value={contextValue}>
+ <Markdown style={markdownStyles} rules={rules}>
+ {text}
+ </Markdown>
+ </MessageContext.Provider>
</GestureTouchableOpacity>
</View>
</TouchableWithoutFeedback>
diff --git a/native/markdown/markdown-context.js b/native/markdown/markdown-context.js
--- a/native/markdown/markdown-context.js
+++ b/native/markdown/markdown-context.js
@@ -9,6 +9,7 @@
+linkModalActive: { [key: string]: boolean },
+setLinkPressActive: SetState<{ [key: string]: boolean }>,
+linkPressActive: { [key: string]: boolean },
+
+setSpoilerRevealed: SetState<{ [key: string]: { [key: number]: boolean } }>,
+spoilerRevealed: { [key: string]: { [key: number]: boolean } },
+setSpoilerPressActive: SetState<boolean>,
diff --git a/native/markdown/markdown-spoiler.react.js b/native/markdown/markdown-spoiler.react.js
--- a/native/markdown/markdown-spoiler.react.js
+++ b/native/markdown/markdown-spoiler.react.js
@@ -20,47 +20,58 @@
const messageContext = React.useContext(MessageContext);
const styles = useStyles(unboundStyles);
- const [styleBasedOnState, setStyleBasedOnState] = React.useState(
- styles.spoilerHidden,
- );
-
const { messageID } = messageContext;
const { text, identifier } = props;
+ const castedIdentifier = identifier ? parseInt(identifier) : identifier;
+
const setSpoilerRevealed = markdownContext?.setSpoilerRevealed;
const spoilerRevealed = markdownContext?.spoilerRevealed;
const setSpoilerPressActive = markdownContext?.setSpoilerPressActive;
+ const styleBasedOnSpoilerState = React.useMemo(() => {
+ return castedIdentifier && spoilerRevealed?.[messageID]?.[castedIdentifier]
+ ? null
+ : styles.spoilerHidden;
+ }, [castedIdentifier, spoilerRevealed, messageID, styles.spoilerHidden]);
+
const onSpoilerClick = React.useCallback(() => {
- if (styleBasedOnState === null) {
+ if (styleBasedOnSpoilerState === null) {
setSpoilerPressActive && setSpoilerPressActive(false);
return;
}
- if (spoilerRevealed && setSpoilerRevealed && messageID && identifier) {
+ if (
+ spoilerRevealed &&
+ setSpoilerRevealed &&
+ messageID &&
+ castedIdentifier
+ ) {
setSpoilerRevealed({
...spoilerRevealed,
- [messageID]: { ...spoilerRevealed[messageID], [identifier]: true },
+ [messageID]: {
+ ...spoilerRevealed[messageID],
+ [castedIdentifier]: true,
+ },
});
}
setSpoilerPressActive && setSpoilerPressActive(true);
- setStyleBasedOnState(null);
}, [
+ styleBasedOnSpoilerState,
setSpoilerPressActive,
spoilerRevealed,
setSpoilerRevealed,
messageID,
- identifier,
- styleBasedOnState,
+ castedIdentifier,
]);
const memoizedSpoiler = React.useMemo(() => {
return (
- <Text onPress={onSpoilerClick} style={styleBasedOnState}>
+ <Text onPress={onSpoilerClick} style={styleBasedOnSpoilerState}>
{text}
</Text>
);
- }, [onSpoilerClick, styleBasedOnState, text]);
+ }, [onSpoilerClick, styleBasedOnSpoilerState, text]);
return memoizedSpoiler;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 7, 5:42 PM (17 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5845271
Default Alt Text
D5541.1765129320.diff (4 KB)
Attached To
Mode
D5541: [native] Maintain spoiler reveal state on message tap
Attached
Detach File
Event Timeline
Log In to Comment