-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: developer settings and clean ui
- Loading branch information
Showing
83 changed files
with
1,167 additions
and
280 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
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
97 changes: 97 additions & 0 deletions
97
src/components/General/MultiPressDetector/MultiPressDetector.tsx
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,97 @@ | ||
/** | ||
* MultiPressDetector | ||
* | ||
<MultiPressDetector pressThreshold={3} /> | ||
* | ||
*/ | ||
import React, { PureComponent, PropsWithChildren } from 'react'; | ||
|
||
import { TouchableOpacity } from 'react-native'; | ||
|
||
/* Types ==================================================================== */ | ||
export interface Props extends PropsWithChildren { | ||
pressThreshold?: number; | ||
onMultiPress?: () => void; | ||
} | ||
|
||
export interface State { | ||
pressCount: number; | ||
lastPress: number; | ||
} | ||
|
||
/* Component ==================================================================== */ | ||
class MultiPressDetector extends PureComponent<Props, State> { | ||
declare readonly props: Props & Required<Pick<Props, keyof typeof MultiPressDetector.defaultProps>>; | ||
|
||
static defaultProps: Partial<Props> = { | ||
pressThreshold: 3, | ||
}; | ||
|
||
constructor(props: Props) { | ||
super(props); | ||
|
||
this.state = { | ||
pressCount: 0, | ||
lastPress: 0, | ||
}; | ||
} | ||
|
||
handleButtonPress = () => { | ||
const { pressCount, lastPress } = this.state; | ||
const { pressThreshold } = this.props; | ||
|
||
const currentTime = Date.now(); | ||
const timeDifference = currentTime - lastPress; | ||
|
||
if (timeDifference < 500) { | ||
this.setState( | ||
{ | ||
pressCount: pressCount + 1, | ||
lastPress: currentTime, | ||
}, | ||
() => { | ||
const { pressCount: newPressCount } = this.state; | ||
if (newPressCount === pressThreshold) { | ||
this.executeCallback(); | ||
this.resetPressCount(); | ||
} | ||
}, | ||
); | ||
} else { | ||
this.resetPressCount(currentTime); | ||
} | ||
}; | ||
|
||
resetPressCount = (currentTime = 0) => { | ||
this.setState({ | ||
pressCount: 0, | ||
lastPress: currentTime, | ||
}); | ||
}; | ||
|
||
executeCallback = () => { | ||
const { onMultiPress } = this.props; | ||
|
||
// Call your callback function here | ||
if (typeof onMultiPress === 'function') { | ||
onMultiPress(); | ||
} | ||
}; | ||
|
||
render() { | ||
const { children } = this.props; | ||
|
||
return ( | ||
<TouchableOpacity | ||
hitSlop={{ top: 10, left: 10, right: 10, bottom: 10 }} | ||
activeOpacity={1} | ||
onPress={this.handleButtonPress} | ||
> | ||
{children} | ||
</TouchableOpacity> | ||
); | ||
} | ||
} | ||
|
||
/* Export Component ==================================================================== */ | ||
export default MultiPressDetector; |
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 @@ | ||
export { default as MultiPressDetector, type Props as MultiPressDetectorProps } from './MultiPressDetector'; |
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 StyleService from '@services/StyleService'; | ||
|
||
/* Styles ==================================================================== */ | ||
export default StyleService.create({ | ||
container: { | ||
borderRadius: 11, | ||
backgroundColor: '$tint', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
placeholder: { | ||
backgroundColor: '$grey', | ||
}, | ||
image: { | ||
borderRadius: 11, | ||
}, | ||
border: { | ||
borderColor: '$lightGrey', | ||
borderWidth: 1, | ||
}, | ||
badgeContainer: { | ||
position: 'absolute', | ||
}, | ||
badgeContainerText: { | ||
position: 'absolute', | ||
backgroundColor: '$blue', | ||
borderWidth: 2.5, | ||
borderColor: '$background', | ||
}, | ||
badge: { | ||
tintColor: '$white', | ||
}, | ||
}); |
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
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
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
Oops, something went wrong.