Skip to content

Hint Refactor #3486

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

Merged
merged 42 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
930a844
refactor: rename hint rendering methods for clarity
ethanshar Dec 23, 2024
084f150
fix: add second hint toggle and adjust hint message positioning
ethanshar Dec 25, 2024
26ef738
Update src/components/hint/index.tsx
ethanshar Dec 29, 2024
3414fff
fix: adjust edge margins and target position thresholds in Hint compo…
ethanshar Dec 31, 2024
019f317
Merge branch 'master' into fix/hint_position
ethanshar Jan 1, 2025
a08f6f5
Add minimum width to Hint component for better layout consistency
ethanshar Jan 2, 2025
f651253
Merge branch 'master' into fix/hint_position
ethanshar Jan 12, 2025
5afbf8f
Convert Hint class component to a function component
ethanshar Jan 13, 2025
c2c3d9b
Separate old Hint code to another file
ethanshar Jan 13, 2025
80ed235
export error for hint wrap with asBaseComponent
ethanshar Jan 13, 2025
40b18be
Extract types to another file
ethanshar Jan 13, 2025
139b8ac
Extract animation logic to useHintAnimation
ethanshar Jan 13, 2025
06006e0
Add useHintLayout hook to manage hint layout state and measurements
ethanshar Jan 13, 2025
3228021
Move HintProps to types
ethanshar Jan 13, 2025
26ceaac
cleanups
ethanshar Jan 13, 2025
1543cea
Add useHintAccessibility hook for improved accessibility handling
ethanshar Jan 13, 2025
cde322d
Add useHintPosition hook for dynamic hint positioning logic
ethanshar Jan 13, 2025
4b38f7b
Refactor and extract HintMockChildren component
ethanshar Jan 13, 2025
598312d
Add HintAnchor component for improved hint rendering and management
ethanshar Jan 14, 2025
5d230ce
Fix render overlay not rendered
ethanshar Jan 16, 2025
56bc7d9
Refactor Hint components for improved structure and layout handling
ethanshar Jan 21, 2025
4ea0f45
Refactor Hint components to use LayoutRectangle for target layout and…
ethanshar Jan 21, 2025
a9811ce
Refactor Hint components to replace TARGET_POSITIONS with TargetAlign…
ethanshar Jan 21, 2025
c6e1eca
Refactor HintAnchor and useHintPosition components to improve type de…
ethanshar Jan 21, 2025
0b12ec8
Refactor useHintPosition hook to improve target position calculations…
ethanshar Jan 21, 2025
f5016b2
Refactor useHintPosition hook to remove unused targetLayout prop and …
ethanshar Jan 21, 2025
437ced7
Merge branch 'master' into infra/hint_refactor_part3
ethanshar Jan 21, 2025
e0fb900
Refactor useHintLayout hook to accept props directly and improve targ…
ethanshar Jan 21, 2025
f36d7c7
Update HintsScreen to rename 'Middle Top' to 'Middle Tip' and improve…
ethanshar Jan 21, 2025
ce2d872
Refactor HintBubble import path and clean up useHintPosition hook by …
ethanshar Jan 21, 2025
e231f4b
Refactor useHintLayout hook to initialize target layout state correct…
ethanshar Jan 22, 2025
86bc627
Refactor Hint component drivers and tests; update useHintLayout hook …
ethanshar Jan 23, 2025
afc0866
Update Hint component snapshots
ethanshar Jan 23, 2025
563f758
Refactor useHintPosition hook to unify tip position style variable na…
ethanshar Jan 23, 2025
f3b447c
Add comment to clarify targetScreenToRelativeOffset calculation in us…
ethanshar Jan 23, 2025
c0c1700
Merge branch 'master' into infra/hint_refactor_part3
ethanshar Jan 23, 2025
5c6dac0
Merge branch 'master' into infra/hint_refactor_part3
ethanshar Feb 3, 2025
95f9e5a
HintsScreen - Update hintKey to include showCustomContent and showRea…
ethanshar Feb 3, 2025
094a94b
Merge branch 'master' into infra/hint_refactor_part3
ethanshar Feb 10, 2025
fa45014
Rename useHintAnimation to useHintVisibility and move some code
ethanshar Feb 10, 2025
e4c594d
Fix hint position calculation for RTL
ethanshar Feb 10, 2025
bdd2ff7
Merge branch 'master' into infra/hint_refactor_part3
ethanshar Feb 12, 2025
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
Prev Previous commit
Next Next commit
Refactor useHintLayout hook to accept props directly and improve targ…
…et layout handling
  • Loading branch information
ethanshar committed Jan 21, 2025
commit e0fb9009de5823f755d285b3c79ceb40b8f38b11
13 changes: 8 additions & 5 deletions src/components/hint/hooks/useHintLayout.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {type ElementRef, useState, useCallback, useRef} from 'react';
import type {LayoutChangeEvent, LayoutRectangle, View as RNView} from 'react-native';
import _ from 'lodash';
import {HintProps} from '../types';

export default function useHintLayout(hasBackgroundPress: boolean) {
const [targetLayoutState, setTargetLayout] = useState<LayoutRectangle>();
const [targetLayoutInWindowState, setTargetLayoutInWindow] = useState<LayoutRectangle>();
type UseHintLayoutProps = Pick<HintProps, 'onBackgroundPress' | 'targetFrame'>

export default function useHintLayout({onBackgroundPress, targetFrame}: UseHintLayoutProps) {
const [targetLayoutState, setTargetLayout] = useState<LayoutRectangle | undefined>(targetFrame);
const [targetLayoutInWindowState, setTargetLayoutInWindow] = useState<LayoutRectangle | undefined>(targetFrame);
const [hintMessageWidth, setHintMessageWidth] = useState<number | undefined>();
const targetRef = useRef<ElementRef<typeof RNView> | null>(null);

Expand All @@ -13,7 +16,7 @@ export default function useHintLayout(hasBackgroundPress: boolean) {
setTargetLayout(layout);
}

if (!targetLayoutInWindowState || hasBackgroundPress) {
if (!targetLayoutInWindowState || !!onBackgroundPress) {
setTimeout(() => {
targetRef?.current?.measureInWindow?.((x: number, y: number, width: number, height: number) => {
const targetLayoutInWindow = {x, y, width, height};
Expand All @@ -22,7 +25,7 @@ export default function useHintLayout(hasBackgroundPress: boolean) {
});
}
},
[targetLayoutState, targetLayoutInWindowState, hasBackgroundPress]);
[targetLayoutState, targetLayoutInWindowState, onBackgroundPress]);

const setHintLayout = useCallback(({nativeEvent: {layout}}: LayoutChangeEvent) => {
if (!hintMessageWidth) {
Expand Down
8 changes: 2 additions & 6 deletions src/components/hint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const NewHint = (props: HintProps) => {

const {hintUnmounted, visibleAnimated, animateHint} = useHintAnimation(visible);
const {targetLayoutState, targetLayoutInWindowState, hintMessageWidth, targetRef, onTargetLayout, setHintLayout} =
useHintLayout(!!onBackgroundPress);
useHintLayout({onBackgroundPress, targetFrame});
const {focusAccessibilityOnHint, accessibilityInfo} = useHintAccessibility(message);

useEffect(() => {
Expand All @@ -70,12 +70,8 @@ const NewHint = (props: HintProps) => {
}, [visible]);

const targetLayout = useMemo(() => {
if (targetFrame) {
return targetFrame;
}

return isUsingModal ? targetLayoutInWindowState : targetLayoutState;
}, [isUsingModal, targetLayoutState, targetLayoutInWindowState, targetFrame]);
}, [isUsingModal, targetLayoutState, targetLayoutInWindowState]);

const setTargetRef = useCallback((ref: ElementRef<typeof RNView>) => {
targetRef.current = ref;
Expand Down