Skip to content
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

fix dark mode gradient #2412

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions apps/mobile/src/components/Feed/Posts/PostListCaption.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LinearGradient } from 'expo-linear-gradient';
import { useCallback, useMemo } from 'react';
import React, { useState } from 'react';
import { useColorScheme } from 'nativewind';
import { useCallback, useMemo, useState } from 'react';
import React from 'react';
import { NativeSyntheticEvent, StyleSheet, TextLayoutEventData, View } from 'react-native';
import { graphql, useFragment } from 'react-relay';

Expand All @@ -10,13 +11,15 @@ import { PostListCaptionFragment$key } from '~/generated/PostListCaptionFragment
import { removeNullValues } from '~/shared/relay/removeNullValues';
import { replaceUrlsWithMarkdownFormat } from '~/shared/utils/replaceUrlsWithMarkdownFormat';


type Props = {
feedPostRef: PostListCaptionFragment$key;
};

export function PostListCaption({ feedPostRef }: Props) {
const [isExpanded, setIsExpanded] = useState(false);
const [textHeight, setTextHeight] = useState(0);
const { colorScheme } = useColorScheme();

const toggleExpanded = useCallback(() => {
setIsExpanded((prev) => !prev);
Expand Down Expand Up @@ -50,14 +53,15 @@ export function PostListCaption({ feedPostRef }: Props) {
}, []);

const shouldShowGradient = textHeight > 0 && !isExpanded;
const gradientColors = colorScheme === 'dark' ? ['rgba(0, 0, 0, 0)', 'rgba(0, 0, 0, 1)'] : ['rgba(255, 255, 255, 0)', 'rgba(255, 255, 255, 1)'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we put this in a useMemo? arrays and objects in JS will be recomputed in react unless memoized

better yet could we do something like this:

// mobile/src/hooks/useGradientColorScheme.ts
export function useGradientColorScheme() {
  const { colorScheme } = useColorScheme();
  return useMemo(() => colorScheme === 'dark' ? ['rgba(0, 0, 0, 0)', 'rgba(0, 0, 0, 1)'] : ['rgba(255, 255, 255, 0)', 'rgba(255, 255, 255, 1)'], [colorScheme])
}


return (
<GalleryTouchableOpacity
onPress={toggleExpanded}
activeOpacity={0.7}
eventElementId="sa"
eventName="saaa"
eventContext="Feed"
eventElementId={null}
eventName={null}
eventContext={null}
>
<View key={isExpanded ? 'expanded' : 'collapsed'} className="px-4 pb-4">
<ProcessedText
Expand All @@ -68,7 +72,7 @@ export function PostListCaption({ feedPostRef }: Props) {
/>
{shouldShowGradient ? (
<LinearGradient
colors={['rgba(255, 255, 255, 0)', 'rgba(255, 255, 255, 1)']}
colors={gradientColors}
start={{ x: 0, y: 0 }}
end={{ x: 0, y: 1 }}
locations={[0.4, 1]}
Expand Down
Loading