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

feat: Adaptation de Papillon pour les tablettes #349

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6213be5
autorisation du mode paysage
Kgeek33 Oct 29, 2024
8bbd009
nouvelle formule de détection d'une tablette
Kgeek33 Oct 29, 2024
6901fea
intégration changement automatique de rotation sur Header.tsx
Kgeek33 Oct 29, 2024
dc13286
intégration changement automatique de rotation sur PapillonTabNavigat…
Kgeek33 Oct 29, 2024
9a6fd6c
quelques optimisations
Kgeek33 Oct 30, 2024
d06c531
Merge branch 'main' into feat/tablet
Kgeek33 Nov 3, 2024
0e0ae8c
Merge branch 'main' into feat/tablet
Kgeek33 Nov 11, 2024
4cc0274
Merge branch 'main' into feat/tablet
Kgeek33 Nov 11, 2024
e326751
code correct pour les devoirs
Kgeek33 Nov 11, 2024
95592d2
affichage correct de l'emploi du temps
Kgeek33 Nov 11, 2024
2dacdac
bon code pour détecter les tablet
Kgeek33 Nov 11, 2024
2dd3e90
Merge branch 'main' into feat/tablet
Kgeek33 Nov 11, 2024
f43c819
Merge branch 'PapillonApp:main' into feat/tablet
Kgeek33 Nov 15, 2024
1ba45d6
Merge branch 'main' into feat/tablet
Kgeek33 Nov 16, 2024
9fd16ab
affichage correct de "Voici les établissements[...]"
Kgeek33 Nov 17, 2024
a492677
Affichage correct du "Quelle est ta[...]"
Kgeek33 Nov 17, 2024
44249b1
même chose pour skolengo
Kgeek33 Nov 17, 2024
29b1b83
Affichage correct de "Dans quelle ville[...]"
Kgeek33 Nov 17, 2024
9401516
affichage correct de la page pour indiquer l'url
Kgeek33 Nov 17, 2024
b08f1ed
Merge branch 'main' into feat/tablet
Kgeek33 Nov 18, 2024
3020b95
Merge branch 'main' into feat/tablet
Kgeek33 Nov 21, 2024
fde95c6
Merge branch 'main' into feat/tablet
Kgeek33 Nov 25, 2024
6652754
Merge branch 'main' into feat/tablet
Kgeek33 Nov 26, 2024
17aeb78
Merge branch 'main' into feat/tablet
Kgeek33 Nov 29, 2024
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 app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"slug": "papillonvex",
"scheme": "papillon",
"version": "7.5.0",
"orientation": "portrait",
"orientation": "default",
"icon": "./assets/icon.png",
"userInterfaceStyle": "automatic",
"primaryColor": "#32AB8E",
Expand Down
16 changes: 14 additions & 2 deletions src/components/Home/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,21 @@ const Header: React.FC<{
const [addons] = useState<AddonHomePageInfo[]>([]);
const [addonsTitle, setAddonsTitle] = useState<string[]>([]);
const [click, setClick] = useState<false | true>(false);
const [tablet, setTablet] = useState<boolean>(false);

const dims = Dimensions.get("window");
const tablet = dims.width > 600;
useEffect(() => {
const updateTabletOrientation = () => {
const dims = Dimensions.get("screen");
const tabletWidth = dims.width;
const tabletHeight = dims.height;
const tabletDiagl = (tabletWidth / tabletHeight) * 10;
setTablet(tabletDiagl >= 6.9);
};
updateTabletOrientation(); // 1ère fois qu'on arrive sur la page

const subscription = Dimensions.addEventListener("change", updateTabletOrientation); // Dès qu'on change de rotation
return () => subscription.remove(); // Permet d'éviter les fuites de mémoire
}, []);

useEffect(() => {
// On récupère le fichier principal de chaque extension.
Expand Down
25 changes: 8 additions & 17 deletions src/router/helpers/PapillonTabNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,32 +237,20 @@ const BasePapillonBar: React.FC<Omit<ReturnType<typeof useNavigationBuilder>, "N
);
};

export const LargePapillonBar: React.FC<Omit<ReturnType<typeof useNavigationBuilder>, "NavigationContent">> = ({ state, descriptors, navigation }) => {
const LargePapillonBar: React.FC<Omit<ReturnType<typeof useNavigationBuilder>, "NavigationContent">> = ({ state, descriptors, navigation }) => {
const theme = useTheme();
const insets = useSafeAreaInsets();

const account = useCurrentAccount(store => store.account!);
const [shouldShowLabel, setShouldShowLabel] = React.useState(true);

const [transparentTabBar, setTransparentTabBar] = React.useState(false);
const [hideTabBar, setHideTabBar] = React.useState(false);

const [showTabBackground, setShowTabBackground] = React.useState(false);
const [hideTabBar, setHideTabBar] = useState(false);

useEffect(() => {
setShouldShowLabel(!account.personalization.hideTabTitles);
setShowTabBackground(account.personalization.showTabBackground ?? false);
setTransparentTabBar(account.personalization.transparentTabBar ?? false);
setHideTabBar(account.personalization.hideTabBar ?? false);
}, [account.personalization]);

const bottomAnim = useSharedValue(1);

const animatedStyles = useAnimatedStyle(() => ({
opacity: withTiming(bottomAnim.value, { duration: 200 }),
}));

React.useEffect(() => {
useEffect(() => {
bottomAnim.value = hideTabBar ? 0 : 1;
}, [hideTabBar]);

Expand Down Expand Up @@ -434,8 +422,11 @@ const BottomTabNavigator: React.ComponentType<any> = ({
screenOptions,
...rest
}) => {
const dims = Dimensions.get("window");
const tablet = dims.width > 600;
const dims = Dimensions.get("screen");
const tabletWidth = dims.width;
const tabletHeight = dims.height;
const tabletDiagl = (tabletWidth / tabletHeight) * 10;
const tablet = tabletDiagl >= 6.9;
const mainNavigator = useRef(null);

// Track previous index to determine direction
Expand Down
7 changes: 5 additions & 2 deletions src/router/screens/account/stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ const AccountStackScreen: Screen<"AccountStack"> = () => {
}
}, [params]);

const dims = Dimensions.get("window");
const tablet = dims.width > 600;
const dims = Dimensions.get("screen");
const tabletWidth = dims.width;
const tabletHeight = dims.height;
const tabletDiagl = (tabletWidth / tabletHeight) * 10;
const tablet = tabletDiagl >= 6.9;

let newAccountScreens = screens;

Expand Down
18 changes: 12 additions & 6 deletions src/views/account/Homeworks/Homeworks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ const formatDate = (date: string | number | Date): string => {

const WeekView: Screen<"Homeworks"> = ({ route, navigation }) => {
const flatListRef: React.MutableRefObject<FlatList> = useRef(null) as any as React.MutableRefObject<FlatList>;
const { width } = Dimensions.get("window");
const finalWidth = width - (width > 600 ? (
320 > width * 0.35 ? width * 0.35 :

const dims = Dimensions.get("screen");
const tabletWidth = dims.width;
const tabletHeight = dims.height;
const tabletDiagl = (tabletWidth / tabletHeight) * 10;
const tablet = tabletDiagl >= 6.9;
const finalWidth = tabletWidth - (tablet ? (
320 > tabletWidth * 0.35 ? tabletWidth * 0.35 :
320
) : 0);

const insets = useSafeAreaInsets();

const outsideNav = route.params?.outsideNav;
Expand Down Expand Up @@ -108,7 +114,7 @@ const WeekView: Screen<"Homeworks"> = ({ route, navigation }) => {
length: finalWidth,
offset: finalWidth * index,
index,
}), [width]);
}), [finalWidth]);

const keyExtractor = useCallback((item: any) => item.toString(), []);

Expand Down Expand Up @@ -444,7 +450,7 @@ const WeekView: Screen<"Homeworks"> = ({ route, navigation }) => {
]}
layout={animPapillon(LinearTransition)}
>
{width > 370 ? "Semaine" : "sem."}
{tabletWidth > 370 ? "Semaine" : "sem."}
</Reanimated.Text>

<Reanimated.View
Expand Down Expand Up @@ -513,7 +519,7 @@ const WeekView: Screen<"Homeworks"> = ({ route, navigation }) => {
/>
}

{showPickerButtons && !searchHasFocus && width > 330 &&
{showPickerButtons && !searchHasFocus && tabletWidth > 330 &&
<Reanimated.View
layout={animPapillon(LinearTransition)}
entering={animPapillon(FadeInLeft).delay(100)}
Expand Down
9 changes: 6 additions & 3 deletions src/views/account/Homeworks/HomeworksHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ import { epochWMToCalendarWeekNumber } from "@/utils/epochWeekNumber";
const HeaderCalendar: React.FC<{ epochWeekNumber: number, oldPageIndex: number, showPicker: () => void, changeIndex: (index: number) => void }> = ({ epochWeekNumber, oldPageIndex, showPicker, changeIndex }) => {
const { colors } = useTheme();

const dims = Dimensions.get("window");
const tablet = dims.width > 600;
const dims = Dimensions.get("screen");
const tabletWidth = dims.width;
const tabletHeight = dims.height;
const tabletDiagl = (tabletWidth / tabletHeight) * 10;
const tablet = tabletDiagl >= 6.9;

const index = epochWeekNumber;

return (
<Reanimated.View
style={{
width: Dimensions.get("window").width - 50 - (tablet ? 400 : 0),
width: tabletWidth - 50 - (tablet ? 400 : 0),
alignItems: "center",
justifyContent: "center",
}}
Expand Down
106 changes: 60 additions & 46 deletions src/views/account/Lessons/Lessons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ const Lessons: Screen<"Lessons"> = ({ route, navigation }) => {
const loadedWeeks = useRef<Set<number>>(new Set());
const currentlyLoadingWeeks = useRef<Set<number>>(new Set());

const dims = Dimensions.get("screen");
const tabletWidth = dims.width;
const tabletHeight = dims.height;
const tabletDiagl = (tabletWidth / tabletHeight) * 10;
const tablet = tabletDiagl >= 6.9;
const finalWidth = tabletWidth - (tablet ? (
320 > tabletWidth * 0.35 ? tabletWidth * 0.35 :
320
) : 0);

useEffect(() => {
// add all week numbers in timetables to loadedWeeks
for (const week in timetables) {
Expand Down Expand Up @@ -77,8 +87,8 @@ const Lessons: Screen<"Lessons"> = ({ route, navigation }) => {
const loadTimetableWeek = async (weekNumber: number, force = false) => {
if (
(currentlyLoadingWeeks.current.has(weekNumber) ||
loadedWeeks.current.has(weekNumber)) &&
!force
loadedWeeks.current.has(weekNumber)) &&
!force
) {
return;
}
Expand Down Expand Up @@ -127,51 +137,55 @@ const Lessons: Screen<"Lessons"> = ({ route, navigation }) => {
return date;
});
});
const renderItem = useCallback(({ item: date }: { item: Date }) => {
const weekNumber = getWeekFromDate(date);
return (
<View style={{ width: Dimensions.get("window").width }}>
<Page
paddingTop={outsideNav ? 80 : insets.top + 56}
current={date.getTime() === pickerDate.getTime()}
date={date}
day={getAllLessonsForDay(date)}
weekExists={
timetables[weekNumber] && timetables[weekNumber].length > 0
}
refreshAction={() => loadTimetableWeek(weekNumber, true)}
loading={loadingWeeks.includes(weekNumber)}
/>
</View>
);
},
[
pickerDate,
timetables,
loadingWeeks,
outsideNav,
insets,
getAllLessonsForDay,
loadTimetableWeek,
],
const renderItem = useCallback(
({ item: date }: { item: Date }) => {
const weekNumber = getWeekFromDate(date);
return (
<View style={{ width: finalWidth, height: "100%" }}>
<Page
paddingTop={outsideNav ? 80 : insets.top + 56}
current={date.getTime() === pickerDate.getTime()}
date={date}
day={getAllLessonsForDay(date)}
weekExists={
timetables[weekNumber] && timetables[weekNumber].length > 0
}
refreshAction={() => loadTimetableWeek(weekNumber, true)}
loading={loadingWeeks.includes(weekNumber)}
/>
</View>
);
},
[
pickerDate,
timetables,
loadingWeeks,
outsideNav,
insets,
finalWidth,
getAllLessonsForDay,
loadTimetableWeek,
]
);

const onViewableItemsChanged = useCallback(({ viewableItems }: { viewableItems: ViewToken<Date>[] }) => {
if (viewableItems.length > 0) {
const newDate = viewableItems[0].item;
setPickerDate(newDate);
loadTimetableWeek(getWeekFromDate(newDate), false);
}
},
[loadTimetableWeek],
const onViewableItemsChanged = useCallback(
({ viewableItems }: { viewableItems: ViewToken<Date>[] }) => {
if (viewableItems.length > 0) {
const newDate = viewableItems[0].item;
setPickerDate(newDate);
loadTimetableWeek(getWeekFromDate(newDate), false);
}
},
[loadTimetableWeek]
);

const getItemLayout = useCallback((_: any, index: number) => ({
length: Dimensions.get("window").width,
offset: Dimensions.get("window").width * index,
index,
}),
[],
const getItemLayout = useCallback(
(_: any, index: number) => ({
length: finalWidth,
offset: finalWidth * index,
index,
}),
[finalWidth]
);

return (
Expand Down Expand Up @@ -238,8 +252,8 @@ const Lessons: Screen<"Lessons"> = ({ route, navigation }) => {
label: "Importer un iCal",
onPress: () => {
navigation.navigate("LessonsImportIcal", {});
}
}
},
},
]}
>
<PapillonHeaderAction
Expand Down Expand Up @@ -284,7 +298,7 @@ const Lessons: Screen<"Lessons"> = ({ route, navigation }) => {
newDate.setHours(0, 0, 0, 0);
setPickerDate(newDate);
const index = data.findIndex(
(d) => d.getTime() === newDate.getTime(),
(d) => d.getTime() === newDate.getTime()
);
if (index !== -1) {
flatListRef.current?.scrollToIndex({ index, animated: true });
Expand Down
7 changes: 5 additions & 2 deletions src/views/account/Lessons/LessonsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ interface HeaderCalendarProps {
}

const HeaderCalendar: React.FC<HeaderCalendarProps> = () => {
const dims = Dimensions.get("window");
const tablet = dims.width > 600;
const dims = Dimensions.get("screen");
const tabletWidth = dims.width;
const tabletHeight = dims.height;
const tabletDiagl = (tabletWidth / tabletHeight) * 10;
const tablet = tabletDiagl >= 6.9;

return (
<Reanimated.View
Expand Down
Loading