-
Notifications
You must be signed in to change notification settings - Fork 734
Feat/new toast #1696
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
Feat/new toast #1696
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5b45945
add assets for new toast component
ethanshar 26e3c36
New toast implementation
ethanshar f954a36
New toast example screen
ethanshar d1c2340
New toast genertate types
ethanshar b5c7468
Add toast api file
ethanshar 32627e0
Remove duplicate condition check
ethanshar 539cd8d
PR Review fix for onDismiss
ethanshar 03aa268
Merge branch 'master' into feat/NewToast
ethanshar 1528a37
Remove redundant View and throttleTime prop
ethanshar 39e8576
Pass only relevant props to useToastAnimation
ethanshar 81d8b89
Use our Icon component instead of Image
ethanshar ead4e56
rename setDismissTimer to setTimer
ethanshar 6a3879c
Add proper prop for triggering haptic feedback
ethanshar 38cf638
minore code review refactor
ethanshar 45b1c4d
Remove loader colors const
ethanshar 5207989
Update toast generated types
ethanshar a045f60
Merge branch 'master' into feat/NewToast
ethanshar 4476d2b
Refactor useToastPreset hook and how we use it
ethanshar f3b1991
Use PanView only for the actual toast and not its attachment
ethanshar 62a1524
Merge branch 'master' into feat/NewToast
ethanshar 5d382af
Fix Constants import
ethanshar 60b51cf
Remove redundant const
ethanshar 8f0f775
rename ToastPresets to be plural and export them for users
ethanshar f4d12fa
Fix toast animation with an attatchment
ethanshar 7a1362e
Fix toast toggle delay due to async state change
ethanshar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
191 changes: 191 additions & 0 deletions
191
demo/src/screens/incubatorScreens/IncubatorToastScreen.tsx
This file contains hidden or 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,191 @@ | ||
import React, {Component} from 'react'; | ||
import {ScrollView, StyleSheet} from 'react-native'; | ||
import {Assets, Colors, Typography, View, Button, Text, Incubator} from 'react-native-ui-lib'; | ||
import {renderMultipleSegmentOptions, renderBooleanOption, renderRadioGroup} from '../ExampleScreenPresenter'; | ||
|
||
const {Toast} = Incubator; | ||
|
||
const TOAST_ACTIONS = { | ||
label: {label: 'Undo', onPress: () => console.warn('undo')}, | ||
icon: {iconSource: Assets.icons.demo.plus, onPress: () => console.warn('add')} | ||
}; | ||
|
||
const TOAST_MESSAGES = { | ||
general: 'La formule Pass VIP illimité 5 mois est masquée', | ||
success: 'The action completed successfully.', | ||
failure: 'The action could not be completed.', | ||
offline: 'Check Your Internet Connection' | ||
}; | ||
|
||
export default class ToastsScreen extends Component { | ||
state = { | ||
visible: false, | ||
toastPosition: 'bottom' as Incubator.ToastProps['position'], | ||
isCustomContent: false, | ||
showLoader: false, | ||
selectedAction: '', | ||
hasAttachment: false, | ||
selectedPreset: '' as Incubator.ToastProps['preset'], | ||
isSwipeable: true | ||
}; | ||
|
||
toggleVisibility = () => { | ||
this.setState({ | ||
visible: !this.state.visible | ||
}); | ||
}; | ||
|
||
renderCustomContent = () => { | ||
return ( | ||
<View flex padding-10 bg-white> | ||
<Text text60>This is a custom content</Text> | ||
<Text> | ||
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry | ||
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to | ||
make a type specimen book. | ||
</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
renderAboveToast = () => { | ||
return ( | ||
<View flex bottom right paddingB-50 paddingR-20 pointerEvents={'box-none'}> | ||
<Button iconSource={Assets.icons.demo.dashboard} color={Colors.white} style={{height: 50, width: 50}}/> | ||
</View> | ||
); | ||
}; | ||
|
||
renderBelowToast = () => { | ||
return ( | ||
<View> | ||
<Text>Attachment below toast</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
renderAttachment = () => { | ||
const {toastPosition, hasAttachment} = this.state; | ||
if (hasAttachment) { | ||
if (toastPosition === 'bottom') { | ||
return this.renderAboveToast(); | ||
} else { | ||
return this.renderBelowToast(); | ||
} | ||
} | ||
}; | ||
|
||
getAction = () => { | ||
const {selectedAction} = this.state; | ||
return TOAST_ACTIONS[selectedAction]; | ||
}; | ||
|
||
getMessage = () => { | ||
const {selectedPreset} = this.state; | ||
|
||
return TOAST_MESSAGES[selectedPreset] || TOAST_MESSAGES.general; | ||
}; | ||
|
||
renderToast = () => { | ||
const {visible, toastPosition, showLoader, isCustomContent, hasAttachment, selectedPreset, isSwipeable} = | ||
this.state; | ||
const action = this.getAction(); | ||
|
||
return ( | ||
<Toast | ||
key={`${toastPosition}-${isCustomContent}-${hasAttachment}`} | ||
visible={visible} | ||
position={toastPosition} | ||
message={this.getMessage()} | ||
showLoader={showLoader} | ||
renderAttachment={this.renderAttachment} | ||
action={action} | ||
preset={selectedPreset} | ||
swipeable={isSwipeable} | ||
onDismiss={this.toggleVisibility} | ||
autoDismiss={3500} | ||
// backgroundColor={Colors.green70} | ||
// iconColor={Colors.green20} | ||
// style={{borderWidth: 1, borderColor: Colors.grey30}} | ||
// messageStyle={Typography.text80BO} | ||
> | ||
{isCustomContent ? this.renderCustomContent() : undefined} | ||
</Toast> | ||
); | ||
}; | ||
|
||
renderToggleButton = () => { | ||
return ( | ||
<View centerH marginT-s5> | ||
<Button | ||
testID={`uilib.showToast`} | ||
marginT-10 | ||
marginB-10 | ||
label={'Toggle toast'} | ||
onPress={this.toggleVisibility} | ||
throttleTime={0} | ||
lidord-wix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<View flex padding-page> | ||
<Text h1 marginB-s4> | ||
Toast | ||
</Text> | ||
|
||
<View flex style={styles.scrollViewContainer}> | ||
<ScrollView contentContainerStyle={styles.scrollView}> | ||
{renderMultipleSegmentOptions.call(this, 'Toast Position', 'toastPosition', [ | ||
{label: 'Bottom', value: 'bottom'}, | ||
{label: 'Top', value: 'top'} | ||
])} | ||
|
||
{renderBooleanOption.call(this, 'Show Loader', 'showLoader')} | ||
{renderBooleanOption.call(this, 'Use custom content', 'isCustomContent')} | ||
{renderBooleanOption.call(this, 'With an attachment', 'hasAttachment')} | ||
{renderBooleanOption.call(this, 'Swipeable', 'isSwipeable')} | ||
|
||
{renderRadioGroup.call(this, | ||
'Action', | ||
'selectedAction', | ||
{None: '', Label: 'label', Icon: 'icon'}, | ||
{isRow: true})} | ||
|
||
<Text h3 marginV-s2> | ||
Presets | ||
</Text> | ||
|
||
{renderMultipleSegmentOptions.call(this, '', 'selectedPreset', [ | ||
{label: 'None', value: ''}, | ||
{label: 'General', value: 'general'}, | ||
{label: 'Success', value: 'success'}, | ||
{label: 'Failure', value: 'failure'}, | ||
{label: 'Offline', value: 'offline'} | ||
])} | ||
|
||
{this.renderToggleButton()} | ||
</ScrollView> | ||
</View> | ||
{this.renderToast()} | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
scrollView: { | ||
paddingBottom: 80 | ||
}, | ||
color: { | ||
width: 30, | ||
height: 30, | ||
borderRadius: 15 | ||
}, | ||
selected: { | ||
borderWidth: 2, | ||
borderColor: Colors.grey10 | ||
} | ||
}); |
This file contains hidden or 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 hidden or 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
16 changes: 16 additions & 0 deletions
16
generatedTypes/src/incubator/toast/helpers/useToastAnimation.d.ts
This file contains hidden or 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,16 @@ | ||
import { Animated } from 'react-native'; | ||
import { ToastProps } from '../types'; | ||
interface UseToastAnimationProps extends Pick<ToastProps, 'visible' | 'preset' | 'position' | 'onAnimationEnd'> { | ||
toastHeight: number; | ||
playAccessibilityFeatures: () => void; | ||
setDismissTimer: () => void; | ||
} | ||
declare const _default: ({ visible, preset, position, toastHeight, onAnimationEnd, setDismissTimer, playAccessibilityFeatures }: UseToastAnimationProps) => { | ||
isAnimating: boolean | undefined; | ||
toggleToast: (show?: boolean, { delay }?: { | ||
delay?: number | undefined; | ||
}) => void; | ||
toastOpacity: Animated.AnimatedInterpolation; | ||
toastTranslateY: Animated.AnimatedInterpolation; | ||
}; | ||
export default _default; |
8 changes: 8 additions & 0 deletions
8
generatedTypes/src/incubator/toast/helpers/useToastPresets.d.ts
This file contains hidden or 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,8 @@ | ||
import 'react'; | ||
import { ToastProps } from '../types'; | ||
declare const _default: ({ preset, icon, iconColor, message }: Pick<ToastProps, 'preset' | 'icon' | 'message' | 'iconColor'>) => { | ||
icon: any; | ||
iconColor: any; | ||
accessibilityMessage: string; | ||
}; | ||
export default _default; |
6 changes: 6 additions & 0 deletions
6
generatedTypes/src/incubator/toast/helpers/useToastTimer.d.ts
This file contains hidden or 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,6 @@ | ||
import { ToastProps } from '../types'; | ||
declare const _default: ({ autoDismiss, onDismiss }: Pick<ToastProps, 'autoDismiss' | 'onDismiss'>) => { | ||
clearTimer: () => void; | ||
setDismissTimer: () => void; | ||
}; | ||
export default _default; |
This file contains hidden or 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,7 @@ | ||
import React from 'react'; | ||
import { ToastProps } from './types'; | ||
export { ToastProps }; | ||
declare const _default: React.ComponentClass<ToastProps & { | ||
useCustomTheme?: boolean | undefined; | ||
}, any>; | ||
export default _default; |
This file contains hidden or 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 @@ | ||
/// <reference types="react" /> | ||
import { ImageSourcePropType, StyleProp, TextStyle, ViewStyle } from 'react-native'; | ||
import { ButtonProps } from '../../components/button'; | ||
export declare enum ToastPreset { | ||
GENERAL = "general", | ||
SUCCESS = "success", | ||
FAILURE = "failure", | ||
OFFLINE = "offline" | ||
} | ||
export interface ToastProps { | ||
/** | ||
* Whether to show or hide the toast | ||
*/ | ||
visible?: boolean; | ||
/** | ||
* The position of the toast. 'top' or 'bottom'. | ||
*/ | ||
position?: 'top' | 'bottom'; | ||
/** | ||
* Toast message | ||
*/ | ||
message?: string; | ||
/** | ||
* Toast message style | ||
*/ | ||
messageStyle?: StyleProp<TextStyle>; | ||
/** | ||
* should message be centered in the toast | ||
*/ | ||
centerMessage?: boolean; | ||
/** | ||
* custom zIndex for toast | ||
*/ | ||
zIndex?: number; | ||
/** | ||
* Custom elevation for Android | ||
*/ | ||
elevation?: number; | ||
/** | ||
* a single action for the user (loader will override this) | ||
*/ | ||
action?: ButtonProps; | ||
/** | ||
* should show a loader | ||
*/ | ||
showLoader?: boolean; | ||
/** | ||
* callback for dismiss action | ||
*/ | ||
onDismiss?: () => void; | ||
/** | ||
* whether to make the toast swipeable | ||
* require to pass onDismiss method to control visibility | ||
*/ | ||
swipeable?: boolean; | ||
/** | ||
* number of milliseconds to automatically invoke the onDismiss callback | ||
*/ | ||
autoDismiss?: number; | ||
/** | ||
* callback for end of component animation | ||
*/ | ||
onAnimationEnd?: (visible?: boolean) => void; | ||
/** | ||
* render a custom view that will appear permanently above or below a Toast, | ||
* depends on the Toast's position, and animate with it when the Toast is made visible or dismissed | ||
*/ | ||
renderAttachment?: () => JSX.Element | undefined; | ||
/** | ||
* The preset look for GENERAL, SUCCESS and FAILURE (Toast.presets.xxx) | ||
*/ | ||
preset?: ToastPreset; | ||
/** | ||
* Test Id for component | ||
*/ | ||
testID?: string; | ||
/** | ||
* Toast style | ||
*/ | ||
style?: StyleProp<ViewStyle>; | ||
/** | ||
* Toast container style | ||
*/ | ||
containerStyle?: StyleProp<ViewStyle>; | ||
/** | ||
* a left icon | ||
*/ | ||
icon?: ImageSourcePropType; | ||
/** | ||
* icon tint color | ||
*/ | ||
iconColor: string; | ||
/** | ||
* The background color of the toast | ||
*/ | ||
backgroundColor: string; | ||
} |
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.