Skip to content

Add HapticType #1277

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 2 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions demo/src/screens/componentScreens/HapticScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import _ from 'lodash';
import React, {Component} from 'react';
import {ScrollView} from 'react-native';
import {View, Text, Button, HapticService} from 'react-native-ui-lib';
import {View, Text, Button, HapticService, HapticType} from 'react-native-ui-lib';

export default class HapticScreen extends Component {
onPress = ({method}: {method: string}) => {
HapticService.triggerHaptic(method, 'HapticScreen');
onPress = ({hapticType}: {hapticType: HapticType}) => {
HapticService.triggerHaptic(hapticType, 'HapticScreen');
};

render() {
Expand All @@ -16,8 +16,8 @@ export default class HapticScreen extends Component {
Haptic Screen
</Text>

{_.map(HapticService.HapticMethods, method => {
return <Button marginV-8 marginH-60 label={method} key={method} onPress={() => this.onPress({method})}/>;
{_.map(HapticService.HapticType, hapticType => {
return <Button marginV-8 marginH-60 label={hapticType} key={hapticType} onPress={() => this.onPress({hapticType})}/>;
})}
</View>
</ScrollView>
Expand Down
13 changes: 11 additions & 2 deletions generatedTypes/services/HapticService.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
declare function triggerHaptic(hapticMethod: string, componentName: string): void;
export declare enum HapticType {
selection = "selection",
impactLight = "impactLight",
impactMedium = "impactMedium",
impactHeavy = "impactHeavy",
notificationSuccess = "notificationSuccess",
notificationWarning = "notificationWarning",
notificationError = "notificationError"
}
declare function triggerHaptic(hapticType: HapticType, componentName: string): void;
declare const _default: {
HapticMethods: string[];
HapticType: typeof HapticType;
triggerHaptic: typeof triggerHaptic;
};
export default _default;
2 changes: 1 addition & 1 deletion generatedTypes/services/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as LogService } from './LogService';
export { default as HapticService } from './HapticService';
export { default as HapticService, HapticType } from './HapticService';
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export {default as Avatar, AvatarPropTypes, AvatarProps} from './components/avat
export {default as Badge, BadgeProps} from './components/badge';
export {default as Card, CardPropTypes, CardProps, CardSectionProps} from './components/card';
export {default as Constants} from './helpers/Constants';
export {default as HapticService} from './services/HapticService';
export {default as HapticService, HapticType} from './services/HapticService';
export {default as View, ViewPropTypes, ViewProps} from './components/view';
export {default as Text, TextPropTypes, TextProps} from './components/text';
export {default as TouchableOpacity, TouchableOpacityProps} from './components/touchableOpacity';
Expand Down
24 changes: 12 additions & 12 deletions src/services/HapticService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ const options = {
ignoreAndroidSystemSettings: false
};

const HapticMethods = [
'selection',
'impactLight',
'impactMedium',
'impactHeavy',
'notificationSuccess',
'notificationWarning',
'notificationError'
];
export enum HapticType {
selection = 'selection',
impactLight = 'impactLight',
impactMedium = 'impactMedium',
impactHeavy = 'impactHeavy',
notificationSuccess = 'notificationSuccess',
notificationWarning = 'notificationWarning',
notificationError = 'notificationError'
}

function triggerHaptic(hapticMethod: string, componentName: string) {
function triggerHaptic(hapticType: HapticType, componentName: string) {
if (HapticFeedbackPackage) {
HapticFeedbackPackage.trigger(hapticMethod, options);
HapticFeedbackPackage.trigger(hapticType, options);
} else {
console.error(`RNUILib ${componentName}'s requires installing "react-native-haptic-feedback" dependency`);
}
}

export default {
HapticMethods,
HapticType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No migration needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's a new code so it's not in use yet :)

triggerHaptic
};
2 changes: 1 addition & 1 deletion src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {default as LogService} from './LogService';
export {default as HapticService} from './HapticService';
export {default as HapticService, HapticType} from './HapticService';