Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ yarn-error.*
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli
# @end expo-cli
2 changes: 2 additions & 0 deletions app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { StyleSheet } from "react-native";

import EditScreenInfo from "../../components/EditScreenInfo";
import { Text, View } from "../../components/Themed";
import Timeline from "../../components/Timeline";

export default function TabOneScreen() {
return (
<View style={styles.container}>
<Timeline />
<Text className="text-xl font-bold text-blue-700">Tab One</Text>
<View
style={styles.separator}
Expand Down
43 changes: 43 additions & 0 deletions components/Timeline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// *Imports
import React from "react";
import { Text, View } from "react-native";

// *Constants
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const today = new Date();
const todayIndex = today.getDay();

// *Start of the Timeline Function
export default function Timeline() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure if this is included in the component feature, but thinking ahead, we could potentially have a selected state and onSelectedStateChange being passed with the default state being that which corresponds to the current date, but when the user clicks into a previous bubble, they would select a new day which would allow them to view the previous feeds.

const firstDayOfWeek = new Date(today);
firstDayOfWeek.setDate(today.getDate() - todayIndex);

return (
<View className="flex-row space-x-3 items-center">
{days.map((day, index) => {
const dayDate = new Date(firstDayOfWeek);
dayDate.setDate(firstDayOfWeek.getDate() + index);
const dateNumber = dayDate.getDate();

return (
<View key={index} className="flex-col items-center">
<Text className="mb-2 font-semibold">{day}</Text>
<View
className={`w-10 h-10 rounded-full shadow-md shadow-gray-200 flex items-center justify-center ${
todayIndex === index ? "border border-[#5731D6]" : "bg-white"
}`}
>
<Text

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

// *Imports
import React from "react";
import { Text, View, StyleSheet } from "react-native";
import { LinearGradient } from 'expo-linear-gradient';
import MaskedView from "@react-native-masked-view/masked-view";

// *Constants
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const today = new Date();
const todayIndex = today.getDay();

// *Start of the Timeline Function
export default function Timeline() {
  const firstDayOfWeek = new Date(today);
  firstDayOfWeek.setDate(today.getDate() - todayIndex);

  return (
    <View style={styles.container}>
      {days.map((day, index) => {
        const dayDate = new Date(firstDayOfWeek);
        dayDate.setDate(firstDayOfWeek.getDate() + index);
        const dateNumber = dayDate.getDate();

        return (
          <View key={index} style={styles.dayContainer}>
            <Text style={styles.dayText}>{day}</Text>
            <View
              style={[
                styles.circle,
                todayIndex === index && styles.activeBorder,
              ]}
            >
              {todayIndex === index ? (
                <MaskedView
                  style={styles.maskedView}
                  maskElement={
                    <View style={styles.centerText}>
                      <Text style={styles.maskedText}>{dateNumber}</Text>
                    </View>
                  }
                >
                  <LinearGradient
                    colors={["#D372E5", "#5731D6"]}
                    start={{ x: 0, y: 0 }}
                    end={{ x: 1, y: 1 }}
                    style={styles.gradient}
                  />
                </MaskedView>
              ) : (
                <Text style={styles.defaultText}>{dateNumber}</Text>
              )}
            </View>
          </View>
        );
      })}
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flexDirection: "row",
    alignItems: "center",
    gap: 12,
    // justifyContent: "space-around",
  },
  dayContainer: {
    flexDirection: "column",
    alignItems: "center",
  },
  dayText: {
    marginBottom: 8,
    fontWeight: "600",
  },
  circle: {
    width: 40,
    height: 40,
    borderRadius: 20,
    alignItems: "center",
    justifyContent: "center",
    backgroundColor: "white",
    shadowColor: "#gray",
    shadowOffset: { width: 0, height: 2 },
    shadowOpacity: 0.2,
    shadowRadius: 2,
  },
  activeBorder: {
    borderWidth: 2,
    borderColor: "#5731D6",
  },
  maskedView: {
    width: "100%",
    height: "100%",
    alignItems: "center",
    justifyContent: "center",
  },
  gradient: {
    width: 40,
    height: 40,
  },
  centerText: {
    flex: 1,
    alignItems: "center",
    justifyContent: "center",
  },
  maskedText: {
    fontSize: 16,
    fontWeight: "bold",
    textAlign: "center",
    color: "black",
  },
  defaultText: {
    fontSize: 16,
    fontWeight: "bold",
    textAlign: "center",
    color: "black",
  },
});

I found something called MaskedView, which would allow us to have gradient text. For the border, you could probably just add a linear gradient circle behind the selected circle. Here's some example code for the timeline with just the text change. Not sure if you still want to pursue gradient colored text, but it might be worth looking into if we ever have gradient text components/UI in the future.

@AndrewCheung360 AndrewCheung360 Nov 1, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I just noticed that there does seem to be some sort of thing where the circle becomes transparent for the selected day in the little code snippet I pasted, but hopefully when actually used, we could try to fix that

className={`text-center ${
todayIndex === index ? "text-[#5731D6]" : "text-black"
}`}
>
{dateNumber}
</Text>
</View>
</View>
);
})}
</View>
);
}