Skip to content

Commit

Permalink
feat: Auto show mode for transfer buttons (#2000)
Browse files Browse the repository at this point in the history
Transfer buttons now show as per Ishtar Commander. They remember if they were open or minimised from the last use.
  • Loading branch information
NigelBreslaw authored Jul 11, 2024
1 parent d91c3d1 commit 2f76643
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
12 changes: 10 additions & 2 deletions native/app/inventory/pages/details/DetailsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ScreenInfo from "@/app/inventory/pages/details/ScreenInfo.tsx";
import TransferEquipButtons from "@/app/inventory/pages/TransferEquipButtons.tsx";
import type { DestinyItem } from "@/app/inventory/logic/Types.ts";
import { ItemType } from "@/app/bungie/Enums.ts";
import { ShowBottomSheet } from "@/app/store/SettingsSlice.ts";

function showBottomSheet(destinyItem: DestinyItem): boolean {
if (destinyItem.def.itemType === ItemType.SeasonalArtifact) {
Expand Down Expand Up @@ -65,7 +66,7 @@ export default function DetailsView({ route, navigation }: Props) {
}

// BottomSheet animation
const opacity = useSharedValue(0);
const opacity = useSharedValue(useGGStore.getState().showNextBottomSheet === ShowBottomSheet.show ? 1 : 0);
const transferButtonStyle = useAnimatedStyle(() => ({
opacity: interpolate(opacity.value, [0, 1], [0, 1], Extrapolation.CLAMP),
}));
Expand Down Expand Up @@ -115,7 +116,14 @@ export default function DetailsView({ route, navigation }: Props) {
{showBottomSheet(destinyItem) && (
<BottomSheet
ref={bottomSheetRef}
index={0}
index={useGGStore.getState().showNextBottomSheet === ShowBottomSheet.show ? 1 : 0}
onChange={(e) => {
if (e === 0) {
useGGStore.getState().setShowBottomSheet(ShowBottomSheet.minimize);
} else if (e === 1) {
useGGStore.getState().setShowBottomSheet(ShowBottomSheet.show);
}
}}
snapPoints={snapPoints}
animateOnMount={false}
handleStyle={{
Expand Down
4 changes: 3 additions & 1 deletion native/app/store/GGStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { type AccountSlice, createAccountSlice } from "./Account/AccountSlice.ts
import { type AuthenticationSlice, createAuthenticationSlice } from "./Authentication/Slice.ts";
import { type DefinitionsSlice, createDefinitionsSlice } from "./DefinitionsSlice.ts";
import { type UIDataSlice, createUIDataSlice } from "./UIDataSlice.ts";
import { type SettingsSlice, createSettingsSlice } from "./SettingsSlice.ts";

export interface IStore extends AccountSlice, AuthenticationSlice, DefinitionsSlice, UIDataSlice {}
export interface IStore extends AccountSlice, AuthenticationSlice, DefinitionsSlice, UIDataSlice, SettingsSlice {}

export const useGGStore = create<IStore>()(
subscribeWithSelector((...a) => ({
...createAccountSlice(...a),
...createAuthenticationSlice(...a),
...createDefinitionsSlice(...a),
...createUIDataSlice(...a),
...createSettingsSlice(...a),
})),
);
31 changes: 31 additions & 0 deletions native/app/store/SettingsSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { IStore } from "@/app/store/GGStore.ts";
import type { StateCreator } from "zustand";

export type SettingsSliceSetter = Parameters<StateCreator<IStore, [], [], SettingsSlice>>[0];
export type SettingsSliceGetter = Parameters<StateCreator<IStore, [], [], SettingsSlice>>[1];

enum ShowBottomSheetPreference {
Auto = "AUTOMATIC",
AlwaysShowing = "ALWAYS_SHOWING",
AlwaysMinimized = "ALWAYS_MINIMIZED",
}

export enum ShowBottomSheet {
show = "show",
minimize = "minimize",
}

export interface SettingsSlice {
showBottomSheetPreference: ShowBottomSheetPreference;
showNextBottomSheet: ShowBottomSheet;
setShowBottomSheet: (showBottomSheet: ShowBottomSheet) => void;
}

export const createSettingsSlice: StateCreator<IStore, [], [], SettingsSlice> = (set, get) => ({
showBottomSheetPreference: ShowBottomSheetPreference.Auto,
showNextBottomSheet: ShowBottomSheet.show,
setShowBottomSheet: (showBottomSheet: ShowBottomSheet) => {
if (get().showBottomSheetPreference === ShowBottomSheetPreference.Auto)
set({ showNextBottomSheet: showBottomSheet });
},
});

0 comments on commit 2f76643

Please sign in to comment.