Skip to content

Commit

Permalink
chore: update type names and exports
Browse files Browse the repository at this point in the history
  • Loading branch information
enesozturk committed Feb 26, 2021
1 parent e50d650 commit a1bfe66
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/components/flatList/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as HoldMenuFlatList } from './FlatList';
export { default } from './FlatList';
export type { HoldMenuFlatListProps } from './FlatList';
10 changes: 5 additions & 5 deletions src/components/holdItem/HoldItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ import styles from './styles';
import { useDeviceOrientation } from '../../hooks';

// Types
import type { IHoldItem } from './types';
import type { HoldItemProps } from './types';
import styleGuide from '../../styleGuide';
import { useInternal } from '../../hooks';

type Context = { didMeasureLayout: boolean };

const HoldItemChildComponent = ({
const HoldItemComponent = ({
items,
bottom,
containerStyles,
disableMove,
menuAnchorPosition,
children,
}: IHoldItem) => {
}: HoldItemProps) => {
const { state, menuProps } = useInternal();
const isActive = useSharedValue(false);
const containerRef = useAnimatedRef<Animated.View>();
Expand Down Expand Up @@ -273,6 +273,6 @@ const HoldItemChildComponent = ({
);
};

const HoldItemChild = memo(HoldItemChildComponent);
const HoldItem = memo(HoldItemComponent);

export default HoldItemChild;
export default HoldItem;
3 changes: 2 additions & 1 deletion src/components/holdItem/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as HoldItem } from './HoldItem';
export { default } from './HoldItem';
export type { HoldItemProps } from './types';
8 changes: 4 additions & 4 deletions src/components/holdItem/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ViewStyle } from 'react-native';
import { IMenuItem } from '../menu/types';
import { MenuItemProps } from '../menu/types';
import { TransformOriginAnchorPosition } from '../../utils/calculations';

export interface IHoldItem {
export type HoldItemProps = {
/**
* List of context menu items.
* @type MenuItemProps[]
* @default []
*/
items: IMenuItem[];
items: MenuItemProps[];

children: React.ReactElement | React.ReactElement[];

Expand Down Expand Up @@ -57,4 +57,4 @@ export interface IHoldItem {
* bottom={true}
*/
bottom?: boolean;
}
};
4 changes: 2 additions & 2 deletions src/components/menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { TouchableOpacity } from 'react-native';
import { TouchableOpacity as GHTouchableOpacity } from 'react-native-gesture-handler';

import { IMenuItem } from './types';
import { MenuItemProps } from './types';

import styles from './styles';
import { CONTEXT_MENU_STATE, IS_IOS } from '../../constants';
Expand All @@ -16,7 +16,7 @@ const MenuItemComponent = ({
item,
isLast,
}: {
item: IMenuItem;
item: MenuItemProps;
isLast?: boolean;
}) => {
const { state, theme } = useInternal();
Expand Down
8 changes: 4 additions & 4 deletions src/components/menu/MenuList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from '../../constants';

import styles from './styles';
import { IMenuItem } from './types';
import { MenuItemProps } from './types';
import { useInternal } from '../../hooks';
import { deepEqual } from '../../utils/validations';

Expand All @@ -38,7 +38,7 @@ const AnimatedView = Animated.createAnimatedComponent(MenuContainerComponent);
const MenuListComponent = () => {
const { state, theme, menuProps } = useInternal();

const [itemList, setItemList] = React.useState<IMenuItem[]>([]);
const [itemList, setItemList] = React.useState<MenuItemProps[]>([]);

const menuHeight = useDerivedValue(
() => calculateMenuHeight(itemList.length),
Expand Down Expand Up @@ -118,7 +118,7 @@ const MenuListComponent = () => {
return { blurType: theme.value };
}, [theme]);

const setter = (items: IMenuItem[]) => {
const setter = (items: MenuItemProps[]) => {
setItemList(items);
};

Expand All @@ -136,7 +136,7 @@ const MenuListComponent = () => {
() => (
<>
{itemList && itemList.length > 0
? itemList.map((item: IMenuItem, index: number) => {
? itemList.map((item: MenuItemProps, index: number) => {
return (
<MenuItem
key={index}
Expand Down
16 changes: 8 additions & 8 deletions src/components/menu/types.ts → src/components/menu/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { TransformOriginAnchorPosition } from '../../utils/calculations';

export interface IMenuItem {
export type MenuItemProps = {
title: string;
icon?: () => React.ReactNode;
onPress: () => void;
}
};

export interface IMenuList {
items: IMenuItem[];
}
export type MenuListProps = {
items: MenuItemProps[];
};

export interface IMenuInternal {
items: IMenuItem[];
export type MenuInternalProps = {
items: MenuItemProps[];
itemHeight: number;
itemWidth: number;
itemY: number;
itemX: number;
anchorPosition: TransformOriginAnchorPosition;
menuHeight: number;
transformValue: number;
}
};
8 changes: 4 additions & 4 deletions src/components/provider/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { InternalContext } from '../../context/internal';
import { Backdrop } from '../backdrop';

// Utils
import { IHoldMenuProvider } from './types';
import { HoldMenuProviderProps } from './types';
import { StateProps, Action } from './reducer';
import { CONTEXT_MENU_STATE } from '../../constants';
import { IMenuInternal } from '../menu/types';
import { MenuInternalProps } from '../menu/types';
import Menu from '../menu';
export interface Store {
state: StateProps;
Expand All @@ -20,12 +20,12 @@ export interface Store {
const ProviderComponent = ({
children,
theme: selectedTheme,
}: IHoldMenuProvider) => {
}: HoldMenuProviderProps) => {
const state = useSharedValue<CONTEXT_MENU_STATE>(
CONTEXT_MENU_STATE.UNDETERMINED
);
const theme = useSharedValue<'light' | 'dark'>(selectedTheme || 'light');
const menuProps = useSharedValue<IMenuInternal>({
const menuProps = useSharedValue<MenuInternalProps>({
itemHeight: 0,
itemWidth: 0,
itemX: 0,
Expand Down
3 changes: 2 additions & 1 deletion src/components/provider/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as HoldMenuProvider } from './Provider';
export { default } from './Provider';
export type { HoldMenuProviderProps } from './types';
2 changes: 1 addition & 1 deletion src/components/provider/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface IHoldMenuProvider {
export interface HoldMenuProviderProps {
/**
* Theme of hold menu. Effects to backdrop and context menu styles. Optional.
* @type "light" | "dark"
Expand Down
4 changes: 2 additions & 2 deletions src/context/internal.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createContext } from 'react';
import type Animated from 'react-native-reanimated';
import type { CONTEXT_MENU_STATE } from '../constants';
import { IMenuInternal } from '../components/menu/types';
import { MenuInternalProps } from '../components/menu/types';

export type InternalContextType = {
state: Animated.SharedValue<CONTEXT_MENU_STATE>;
theme: Animated.SharedValue<'light' | 'dark'>;
menuProps: Animated.SharedValue<IMenuInternal>;
menuProps: Animated.SharedValue<MenuInternalProps>;
};

// @ts-ignore
Expand Down
7 changes: 0 additions & 7 deletions src/index.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as HoldItem } from './components/holdItem';
export { default as HoldMenuProvider } from './components/provider';
export { default as HoldMenuFlatList } from './components/flatList';
8 changes: 4 additions & 4 deletions src/utils/validations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IMenuItem } from '../components/menu/types';
import { MenuItemProps } from '../components/menu/types';

function fieldAreSame(obj1: IMenuItem, obj2: IMenuItem) {
function fieldAreSame(obj1: MenuItemProps, obj2: MenuItemProps) {
'worklet';
let areObjectsSame = true;

Expand All @@ -22,15 +22,15 @@ function fieldAreSame(obj1: IMenuItem, obj2: IMenuItem) {
return areObjectsSame;
}

function deepEqual(array1: IMenuItem[], array2: IMenuItem[] | null) {
function deepEqual(array1: MenuItemProps[], array2: MenuItemProps[] | null) {
'worklet';
let areEqual = true;

const areArrays = Array.isArray(array1) && Array.isArray(array2);
const areSameLength = areArrays && array2 && array1.length === array2.length;

if (areArrays && areSameLength && array2) {
array1.forEach((menuItem: IMenuItem, index) => {
array1.forEach((menuItem: MenuItemProps, index) => {
const obj1 = menuItem;
const obj2 = array2[index];

Expand Down

0 comments on commit a1bfe66

Please sign in to comment.