From 726e2f9c8b22fb3263b748930039bcecbfa485e2 Mon Sep 17 00:00:00 2001 From: chirag-singhal Date: Thu, 13 Aug 2020 18:14:33 +0530 Subject: [PATCH] use cases for toast android --- .../ToastAndroidExample.android.js | 239 ++++++++++-------- 1 file changed, 138 insertions(+), 101 deletions(-) diff --git a/packages/rn-tester/js/examples/ToastAndroid/ToastAndroidExample.android.js b/packages/rn-tester/js/examples/ToastAndroid/ToastAndroidExample.android.js index 27ac0e49cffe7e..329da7b9cb40ed 100644 --- a/packages/rn-tester/js/examples/ToastAndroid/ToastAndroidExample.android.js +++ b/packages/rn-tester/js/examples/ToastAndroid/ToastAndroidExample.android.js @@ -10,8 +10,6 @@ 'use strict'; -const RNTesterBlock = require('../../components/RNTesterBlock'); -const RNTesterPage = require('../../components/RNTesterPage'); const React = require('react'); const { @@ -21,106 +19,109 @@ const { TouchableWithoutFeedback, } = require('react-native'); -type Props = $ReadOnly<{||}>; -class ToastExample extends React.Component { - render(): React.Node { - return ( - - - - ToastAndroid.show( - 'This is a toast with short duration', - ToastAndroid.SHORT, - ) - }> - Click me. - - - - - ToastAndroid.show( - 'This is a toast with long duration', - ToastAndroid.LONG, - ) - }> - Click me. - - - - - ToastAndroid.showWithGravity( - 'This is a toast with top gravity', - ToastAndroid.SHORT, - ToastAndroid.TOP, - ) - }> - Click me. - - - - - ToastAndroid.showWithGravity( - 'This is a toast with center gravity', - ToastAndroid.SHORT, - ToastAndroid.CENTER, - ) - }> - Click me. - - - - - ToastAndroid.showWithGravity( - 'This is a toast with bottom gravity', - ToastAndroid.SHORT, - ToastAndroid.BOTTOM, - ) - }> - Click me. - - - - - ToastAndroid.showWithGravityAndOffset( - 'This is a toast with x offset', - ToastAndroid.SHORT, - ToastAndroid.CENTER, - 50, - 0, - ) - }> - Click me. - - - - - ToastAndroid.showWithGravityAndOffset( - 'This is a toast with y offset', - ToastAndroid.SHORT, - ToastAndroid.BOTTOM, - 0, - 50, - ) - }> - Click me. - - - - ); - } -} +const ToastWithShortDuration = () => { + return ( + + ToastAndroid.show('Copied to clipboard!', ToastAndroid.SHORT) + }> + Tap to view toast + + ); +}; + +const ToastWithLongDuration = () => { + return ( + ToastAndroid.show('Sending message..', ToastAndroid.LONG)}> + Tap to view toast + + ); +}; + +const ToastWithTopGravity = () => { + return ( + + ToastAndroid.showWithGravity( + 'Download Started..', + ToastAndroid.SHORT, + ToastAndroid.TOP, + ) + }> + Tap to view toast + + ); +}; + +const ToastWithCenterGravity = () => { + return ( + + ToastAndroid.showWithGravity( + 'A problem has been occured while submitting your data.', + ToastAndroid.SHORT, + ToastAndroid.CENTER, + ) + }> + Tap to view toast + + ); +}; + +const ToastWithBottomGravity = () => { + return ( + + ToastAndroid.showWithGravity( + 'Please read the contents carefully.', + ToastAndroid.SHORT, + ToastAndroid.BOTTOM, + ) + }> + Tap to view toast + + ); +}; + +const ToastWithXOffset = () => { + return ( + + ToastAndroid.showWithGravityAndOffset( + 'Alex sent you a friend request', + ToastAndroid.SHORT, + ToastAndroid.TOP, + 250, + 0, + ) + }> + Tap to view toast + + ); +}; + +const ToastWithYOffset = () => { + return ( + + ToastAndroid.showWithGravityAndOffset( + 'There was a problem with your internet connection', + ToastAndroid.SHORT, + ToastAndroid.BOTTOM, + 0, + 100, + ) + }> + Tap to view toast + + ); +}; const styles = StyleSheet.create({ text: { color: 'black', - }, + } }); exports.title = 'Toast Example'; @@ -128,9 +129,45 @@ exports.description = 'Example that demonstrates the use of an Android Toast to provide feedback.'; exports.examples = [ { - title: 'Basic toast', - render: function(): React.Element { - return ; + title: 'Toast with Short Duration', + render(): React.Node { + return ; + }, + }, + { + title: 'Toast with Long Duration', + render(): React.Node { + return ; + }, + }, + { + title: 'Toast with Top Gravity', + render(): React.Node { + return ; + }, + }, + { + title: 'Toast with Center Gravity', + render(): React.Node { + return ; + }, + }, + { + title: 'Toast with Bottom Gravity', + render(): React.Node { + return ; + }, + }, + { + title: 'Toast with X Offset', + render(): React.Node { + return ; + }, + }, + { + title: 'Toast with Y Offset', + render(): React.Node { + return ; }, }, ];