-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
45 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useMemo } from 'react'; | ||
import { TouchableOpacity } from './TouchableOpacity'; | ||
import { TouchableHighlight } from './TouchableHighlight'; | ||
import type { ITouchable } from './types'; | ||
|
||
export const Touchable: ITouchable = (props) => { | ||
const { children, mode = 'opacity', disabled, onPress, style, ...others } = props; | ||
|
||
const _style = useMemo(() => { | ||
return disabled ? [style, { opacity: 0.5 }] : style; | ||
}, [style, disabled]); | ||
|
||
switch (mode) { | ||
case 'none': | ||
return ( | ||
<TouchableOpacity style={_style} disabled={disabled} activeOpacity={1} onPress={onPress} {...others}> | ||
{children} | ||
</TouchableOpacity> | ||
); | ||
case 'highlight': | ||
return ( | ||
<TouchableHighlight style={_style} disabled={disabled} onPress={onPress} {...others}> | ||
{children} | ||
</TouchableHighlight> | ||
); | ||
default: | ||
return ( | ||
<TouchableOpacity style={_style} disabled={disabled} onPress={onPress} {...others}> | ||
{children} | ||
</TouchableOpacity> | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,2 @@ | ||
import { View } from 'react-native'; | ||
import TouchableOpacity from './TouchableOpacity'; | ||
// import { useThrottleFn } from '../../../hooks'; | ||
import type { ITouchable } from './types'; | ||
|
||
export const Touchable: ITouchable = (props) => { | ||
const { children, mode = 'opacity', disabled, onPress, ...others } = props; | ||
|
||
const childElement = disabled ? <View style={{ opacity: 0.5 }}>{children}</View> : children; | ||
|
||
switch (mode) { | ||
// 先放在这里, 目前用不到highlight这种模式 统一opacity就可以 | ||
case 'none': | ||
return ( | ||
<TouchableOpacity disabled={disabled} activeOpacity={1} onPress={onPress} {...others}> | ||
{childElement} | ||
</TouchableOpacity> | ||
); | ||
default: | ||
return ( | ||
<TouchableOpacity disabled={disabled} onPress={onPress} {...others}> | ||
{childElement} | ||
</TouchableOpacity> | ||
); | ||
} | ||
}; | ||
|
||
export default Touchable; | ||
export * from './Touchable'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
import { ReactElement } from 'react'; | ||
import { TouchableOpacityProps, TouchableHighlightProps } from 'react-native'; | ||
|
||
// 交互统一的场景,highlight暂时用不到, 所以没有在ITouchable定义, | ||
interface ITouchableHighlightProps extends TouchableOpacityProps { | ||
interface TDTouchableHighlightProps extends TouchableOpacityProps { | ||
mode?: 'highlight'; | ||
// throttleTime?: number; | ||
onPress?: () => void; | ||
} | ||
interface ITouchableNoneProps extends TouchableOpacityProps { | ||
interface TDTouchableNoneProps extends TouchableOpacityProps { | ||
mode?: 'none'; | ||
// throttleTime?: number; | ||
onPress?: () => void; | ||
} | ||
|
||
interface ITouchableOpacityProps extends TouchableHighlightProps { | ||
interface TDTouchableOpacityProps extends TouchableHighlightProps { | ||
mode?: 'opacity'; | ||
// throttleTime?: number; | ||
onPress?: () => void; | ||
} | ||
|
||
type ITouchable = (props: ITouchableOpacityProps | ITouchableNoneProps) => ReactElement; | ||
type ITouchable = (props: TDTouchableOpacityProps | TDTouchableNoneProps | TDTouchableHighlightProps) => ReactElement; | ||
|
||
export type { ITouchableHighlightProps, ITouchableOpacityProps, ITouchable }; | ||
export type { TDTouchableHighlightProps, TDTouchableOpacityProps, ITouchable }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { View, Text, ScrollView, Image, TextInput, WrapperComponent } from './Base'; | ||
export { Button } from './Button'; | ||
export * from './Base'; | ||
export * from './Button'; | ||
export * from './Touchable'; |