{"id":56995,"date":"2023-03-28T09:28:48","date_gmt":"2023-03-28T03:58:48","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=56995"},"modified":"2023-04-05T09:29:57","modified_gmt":"2023-04-05T03:59:57","slug":"floating-action-button-with-menu-explanation","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/floating-action-button-with-menu-explanation\/","title":{"rendered":"Floating Action Button with Menu Explanation"},"content":{"rendered":"<p id=\"faee\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\"><strong class=\"id hf\">Intro<\/strong><\/p>\n<p class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">We\u2019ll be rebuilding the starbucks app pay button. Not only does this have a floating button, it has 2 other floating buttons, and a circular background cover that shoots out to allow you to focus on the options. These other 2 floating buttons will appear when user will press the floating pay button with animation.Attached a gif file from where you can visualise how the animation will look like when we press the floating pay button<\/p>\n<p id=\"bb93\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-56994\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/ezgif.com-video-to-gif-144x300.gif\" alt=\"Image\" width=\"144\" height=\"300\" \/><\/p>\n<p id=\"bf4c\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\"><strong class=\"id hf\">Setup<\/strong><\/p>\n<p id=\"315e\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">A standard setup,\u00a0<strong class=\"id hf\">react-native-vector-icons library\u00a0<\/strong>for buttons icons and an animated value. This animated value will only go from\u00a0<code class=\"er jh ji jj jk b\">0<\/code>\u00a0to\u00a0<code class=\"er jh ji jj jk b\">1<\/code>\u00a0so we can keep our animation reversible.<\/p>\n<pre class=\"ja jb jc jd ft jl jk jm bn jn jo bi\"><span id=\"357a\" class=\"jp jq he jk b be jr js l jt ju\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">import<\/span> <span class=\"hljs-title.class\">React<\/span>, {useState} <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'react'<\/span>;\r\n<span class=\"hljs-keyword\">import<\/span> {\r\n  <span class=\"hljs-title.class\">StyleSheet<\/span>,\r\n  <span class=\"hljs-title.class\">Text<\/span>,\r\n  <span class=\"hljs-title.class\">View<\/span>,\r\n  <span class=\"hljs-title.class\">Animated<\/span>,\r\n  <span class=\"hljs-title.class\">TouchableWithoutFeedback<\/span>,\r\n  <span class=\"hljs-title.class\">Image<\/span>,\r\n} <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'react-native'<\/span>;\r\n<span class=\"hljs-keyword\">import<\/span> <span class=\"hljs-title.class\">Icon<\/span> <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'react-native-vector-icons\/Ionicons'<\/span>;\r\n\r\n<span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title.function\">App<\/span>(): <span class=\"hljs-variable.constant\">JSX<\/span>.<span class=\"hljs-property\">Element<\/span> {\r\n  <span class=\"hljs-keyword\">const<\/span> [animation] = <span class=\"hljs-title.function\">useState<\/span>(<span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title.class\">Animated<\/span>.<span class=\"hljs-title.class\">Value<\/span>(<span class=\"hljs-number\">0<\/span>));\r\n  <span class=\"hljs-keyword\">return<\/span> (\r\n    <span class=\"hljs-undefined\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{styles.container}\/<\/span>&gt;<\/span><\/span>\r\n  );\r\n}\r\n\r\n<span class=\"hljs-keyword\">const<\/span> styles = <span class=\"hljs-title.class\">StyleSheet<\/span>.<span class=\"hljs-title.function\">create<\/span>({\r\n  <span class=\"hljs-attr\">container<\/span>: {\r\n    <span class=\"hljs-attr\">flex<\/span>: <span class=\"hljs-number\">1<\/span>,\r\n  },\r\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">default<\/span> <span class=\"hljs-title.class\">App<\/span>;<\/span><\/pre>\n<p id=\"3d88\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\"><strong class=\"id hf\">Add Bottom Button<\/strong><\/p>\n<p id=\"3e6f\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">So first we need to add our main floating action button. We won\u2019t be animating this button, but we will be animating the text.<\/p>\n<pre class=\"ja jb jc jd ft jl jk jm bn jn jo bi\"><span id=\"0178\" class=\"jp jq he jk b be jr js l jt ju\" data-selectable-paragraph=\"\">  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{styles.container}<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">TouchableWithoutFeedback<\/span> <span class=\"hljs-attr\">onPress<\/span>=<span class=\"hljs-string\">{toggleOpen}<\/span>&gt;<\/span>\r\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.button,<\/span> <span class=\"hljs-attr\">styles.pay<\/span>]}&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.Text<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.label]}<\/span>&gt;<\/span>Pay<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Animated.Text<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Text<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{styles.payText}<\/span>&gt;<\/span>$5.00<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Text<\/span>&gt;<\/span>\r\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">View<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">TouchableWithoutFeedback<\/span>&gt;<\/span>\r\n  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">View<\/span>&gt;<\/span><\/span><\/pre>\n<p id=\"2226\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">We\u2019ll position our button in the corner and create a reusable style so all of our buttons will be the same shape and size. This will allow us to hide them behind our button then animate them visible. Then to make our button green we just add our\u00a0<code class=\"er jh ji jj jk b\">pay<\/code>\u00a0style to add a background color.<\/p>\n<p id=\"fa74\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">Additionally we position our text absolutely and render it inside of our button. Without adding any\u00a0<code class=\"er jh ji jj jk b\">top\/left\/bottom\/right<\/code>\u00a0values it&#8217;ll float freely but still stay centered.<\/p>\n<pre class=\"ja jb jc jd ft jl jk jm bn jn jo bi\"><span id=\"3b38\" class=\"jp jq he jk b be jr js l jt ju\" data-selectable-paragraph=\"\">label: {\r\n  <span class=\"hljs-attribute\">color<\/span>: <span class=\"hljs-string\">\"#FFF\"<\/span>,\r\n  <span class=\"hljs-attribute\">position<\/span>: <span class=\"hljs-string\">\"absolute\"<\/span>,\r\n  <span class=\"hljs-attribute\">fontSize<\/span>: <span class=\"hljs-number\">18<\/span>,\r\n  <span class=\"hljs-attribute\">backgroundColor<\/span>: <span class=\"hljs-string\">\"transparent\"<\/span>,\r\n},\r\nbutton: {\r\n    <span class=\"hljs-attribute\">width<\/span>: <span class=\"hljs-number\">60<\/span>,\r\n    <span class=\"hljs-attribute\">height<\/span>: <span class=\"hljs-number\">60<\/span>,\r\n    <span class=\"hljs-attribute\">alignItems<\/span>: <span class=\"hljs-string\">\"center\"<\/span>,\r\n    <span class=\"hljs-attribute\">justifyContent<\/span>: <span class=\"hljs-string\">\"center\"<\/span>,\r\n    <span class=\"hljs-attribute\">shadowColor<\/span>: <span class=\"hljs-string\">\"#333\"<\/span>,\r\n    <span class=\"hljs-attribute\">shadowOpacity<\/span>: <span class=\"hljs-number\">0.1<\/span>,\r\n    <span class=\"hljs-attribute\">shadowOffset<\/span>: { <span class=\"hljs-attribute\">x<\/span>: <span class=\"hljs-number\">2<\/span>, <span class=\"hljs-attribute\">y<\/span>: <span class=\"hljs-number\">0<\/span> },\r\n    shadowRadius: 2,\r\n    borderRadius: 30,\r\n    <span class=\"hljs-attribute\">position<\/span>: <span class=\"hljs-string\">\"absolute\"<\/span>,\r\n    <span class=\"hljs-attribute\">bottom<\/span>: <span class=\"hljs-number\">20<\/span>,\r\n    <span class=\"hljs-attribute\">right<\/span>: <span class=\"hljs-number\">20<\/span>,\r\n  },\r\n  payText: {\r\n    <span class=\"hljs-attribute\">color<\/span>: <span class=\"hljs-string\">\"#FFF\"<\/span>,\r\n  },\r\n  pay: {\r\n    backgroundColor: \"#00B15E\",\r\n  },<\/span><\/pre>\n<p id=\"bb33\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\"><strong class=\"id hf\">Add More Buttons<\/strong><\/p>\n<p id=\"71f0\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">Now let&#8217;s add our other buttons. These will need to be animated, so we use an <code class=\"er jh ji jj jk b\">Animated.View<\/code>\u00a0and choose the appropriate icons. Because our\u00a0<code class=\"er jh ji jj jk b\">button<\/code>\u00a0class is positioning everything in the same spot, and we have placed these buttons above our\u00a0<code class=\"er jh ji jj jk b\">pay<\/code> button in the render, they will be rendered behind our\u00a0<code class=\"er jh ji jj jk b\">pay<\/code>\u00a0button.<\/p>\n<pre class=\"ja jb jc jd ft jl jk jm bn jn jo bi\"><span id=\"a717\" class=\"jp jq he jk b be jr js l jt ju\" data-selectable-paragraph=\"\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{styles.container}<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">TouchableWithoutFeedback<\/span>&gt;<\/span>\r\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.button,<\/span> <span class=\"hljs-attr\">styles.other<\/span>]}&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.Text<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.label]}<\/span>&gt;<\/span>Order<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Animated.Text<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Icon<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"food-fork-drink\"<\/span> <span class=\"hljs-attr\">size<\/span>=<span class=\"hljs-string\">{20}<\/span> <span class=\"hljs-attr\">color<\/span>=<span class=\"hljs-string\">\"#555\"<\/span> \/&gt;<\/span>\r\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Animated.View<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">TouchableWithoutFeedback<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">TouchableWithoutFeedback<\/span>&gt;<\/span>\r\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.button,<\/span> <span class=\"hljs-attr\">styles.other<\/span>]}&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.Text<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.label]}<\/span>&gt;<\/span>Reload<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Animated.Text<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Icon<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"reload\"<\/span> <span class=\"hljs-attr\">size<\/span>=<span class=\"hljs-string\">{20}<\/span> <span class=\"hljs-attr\">color<\/span>=<span class=\"hljs-string\">\"#555\"<\/span> \/&gt;<\/span>\r\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Animated.View<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">TouchableWithoutFeedback<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">TouchableWithoutFeedback<\/span> <span class=\"hljs-attr\">onPress<\/span>=<span class=\"hljs-string\">{toggleOpen}<\/span>&gt;<\/span>\r\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.button,<\/span> <span class=\"hljs-attr\">styles.pay<\/span>]}&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.Text<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.label]}<\/span>&gt;<\/span>Pay<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Animated.Text<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Text<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{styles.payText}<\/span>&gt;<\/span>$5.00<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Text<\/span>&gt;<\/span>\r\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">View<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">TouchableWithoutFeedback<\/span>&gt;<\/span>\r\n  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">View<\/span>&gt;<\/span><\/span><\/pre>\n<p id=\"dda9\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">The only thing we need to do is specify their background color.<\/p>\n<pre class=\"ja jb jc jd ft jl jk jm bn jn jo bi\"><span id=\"8662\" class=\"jp jq he jk b be jr js l jt ju\" data-selectable-paragraph=\"\">other: {\r\n    backgroundColor: <span class=\"hljs-string\">\"#FFF\"<\/span>,\r\n  }<\/span><\/pre>\n<p id=\"091e\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\"><strong class=\"id hf\">Add Hidden Background<\/strong><\/p>\n<p id=\"15b5\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">We want a circular animated black opaque background, however, rather than making it hidden via opacity, we\u2019ll just treat it like another button and tuck it behind the rest of the buttons.<\/p>\n<pre class=\"ja jb jc jd ft jl jk jm bn jn jo bi\"><span id=\"498e\" class=\"jp jq he jk b be jr js l jt ju\" data-selectable-paragraph=\"\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{styles.container}<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.background,<\/span> <span class=\"hljs-attr\">bgStyle<\/span>]} \/&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">TouchableWithoutFeedback<\/span>&gt;<\/span>\r\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.button,<\/span> <span class=\"hljs-attr\">styles.other<\/span>, <span class=\"hljs-attr\">orderStyle<\/span>]}&gt;<\/span>\r\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.Text<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.label,<\/span> <span class=\"hljs-attr\">labelStyle<\/span>]}&gt;<\/span>Order<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Animated.Text<\/span>&gt;<\/span>\r\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Icon<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"food-fork-drink\"<\/span> <span class=\"hljs-attr\">size<\/span>=<span class=\"hljs-string\">{20}<\/span> <span class=\"hljs-attr\">color<\/span>=<span class=\"hljs-string\">\"#555\"<\/span> \/&gt;<\/span>\r\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Animated.View<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">TouchableWithoutFeedback<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">TouchableWithoutFeedback<\/span>&gt;<\/span>\r\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.button,<\/span> <span class=\"hljs-attr\">styles.other<\/span>, <span class=\"hljs-attr\">reloadStyle<\/span>]}&gt;<\/span>\r\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.Text<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.label,<\/span> <span class=\"hljs-attr\">labelStyle<\/span>]}&gt;<\/span>Reload<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Animated.Text<\/span>&gt;<\/span>\r\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Icon<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"reload\"<\/span> <span class=\"hljs-attr\">size<\/span>=<span class=\"hljs-string\">{20}<\/span> <span class=\"hljs-attr\">color<\/span>=<span class=\"hljs-string\">\"#555\"<\/span> \/&gt;<\/span>\r\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Animated.View<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">TouchableWithoutFeedback<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">TouchableWithoutFeedback<\/span> <span class=\"hljs-attr\">onPress<\/span>=<span class=\"hljs-string\">{toggleOpen}<\/span>&gt;<\/span>\r\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">View<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.button,<\/span> <span class=\"hljs-attr\">styles.pay<\/span>]}&gt;<\/span>\r\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Animated.Text<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{[styles.label,<\/span> <span class=\"hljs-attr\">labelStyle<\/span>]}&gt;<\/span>Pay<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Animated.Text<\/span>&gt;<\/span>\r\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Text<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{styles.payText}<\/span>&gt;<\/span>$5.00<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Text<\/span>&gt;<\/span>\r\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">View<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">TouchableWithoutFeedback<\/span>&gt;<\/span>\r\n  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">View<\/span>&gt;<\/span><\/span><\/pre>\n<ul class=\"\">\n<li id=\"5e58\" class=\"jv jw he id b ie if ii ij im jx iq jy iu jz iy ka kb kc kd bi\" data-selectable-paragraph=\"\">Basically the same as the button styling.<\/li>\n<\/ul>\n<pre class=\"ja jb jc jd ft jl jk jm bn jn jo bi\"><span id=\"c9ab\" class=\"jp jq he jk b be jr js l jt ju\" data-selectable-paragraph=\"\"><span class=\"hljs-attribute\">background<\/span>: {\r\n  <span class=\"hljs-attribute\">backgroundColor<\/span>: <span class=\"hljs-string\">\"rgba(0,0,0,.2)\"<\/span>,\r\n  <span class=\"hljs-attribute\">position<\/span>: <span class=\"hljs-string\">\"absolute\"<\/span>,\r\n  <span class=\"hljs-attribute\">width<\/span>: <span class=\"hljs-number\">60<\/span>,\r\n  <span class=\"hljs-attribute\">height<\/span>: <span class=\"hljs-number\">60<\/span>,\r\n  <span class=\"hljs-attribute\">bottom<\/span>: <span class=\"hljs-number\">20<\/span>,\r\n  <span class=\"hljs-attribute\">right<\/span>: <span class=\"hljs-number\">20<\/span>,\r\n  <span class=\"hljs-attribute\">borderRadius<\/span>: <span class=\"hljs-number\">30<\/span>,\r\n},<\/span><\/pre>\n<p id=\"829d\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\"><strong class=\"id hf\">Setup Animation on Press<\/strong><\/p>\n<p id=\"b889\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">Because we don\u2019t need to toggle pointer events on this animation we just need to save off on the instance whether or not our menu is opened or closed. Then decide to animate to\u00a0<code class=\"er jh ji jj jk b\">0<\/code>\u00a0or\u00a0<code class=\"er jh ji jj jk b\">1<\/code>. This will produce a reversible animation that also can be interrupted at any point.<\/p>\n<pre class=\"ja jb jc jd ft jl jk jm bn jn jo bi\"><span id=\"7702\" class=\"jp jq he jk b be jr js l jt ju\" data-selectable-paragraph=\"\">  <span class=\"hljs-keyword\">let<\/span> <span class=\"hljs-attr\">_open<\/span>: boolean;\r\n\r\n  <span class=\"hljs-keyword\">const<\/span> <span class=\"hljs-title.function\">toggleOpen<\/span> = () =&gt; {\r\n    <span class=\"hljs-keyword\">if<\/span> (_open) {\r\n      <span class=\"hljs-title.class\">Animated<\/span>.<span class=\"hljs-title.function\">timing<\/span>(animation, {\r\n        <span class=\"hljs-attr\">toValue<\/span>: <span class=\"hljs-number\">0<\/span>,\r\n        <span class=\"hljs-attr\">duration<\/span>: <span class=\"hljs-number\">300<\/span>,\r\n        <span class=\"hljs-attr\">useNativeDriver<\/span>: <span class=\"hljs-literal\">false<\/span>,\r\n      }).<span class=\"hljs-title.function\">start<\/span>();\r\n    } <span class=\"hljs-keyword\">else<\/span> {\r\n      <span class=\"hljs-title.class\">Animated<\/span>.<span class=\"hljs-title.function\">timing<\/span>(animation, {\r\n        <span class=\"hljs-attr\">toValue<\/span>: <span class=\"hljs-number\">1<\/span>,\r\n        <span class=\"hljs-attr\">duration<\/span>: <span class=\"hljs-number\">300<\/span>,\r\n        <span class=\"hljs-attr\">useNativeDriver<\/span>: <span class=\"hljs-literal\">false<\/span>,\r\n      }).<span class=\"hljs-title.function\">start<\/span>();\r\n    }\r\n    _open = !_open;\r\n  };<\/span><\/pre>\n<ul class=\"\">\n<li id=\"e729\" class=\"jv jw he id b ie if ii ij im jx iq jy iu jz iy ka kb kc kd bi\" data-selectable-paragraph=\"\">Our reload button will be closest so we\u2019ll offset it by\u00a0<code class=\"er jh ji jj jk b\">-70<\/code>\u00a0giving us some padding from the pay button. Our order button will be the last button so we just need to offset it by\u00a0<code class=\"er jh ji jj jk b\">-140<\/code>\u00a0so it will bypass the reload button and also have some padding.<\/li>\n<\/ul>\n<p id=\"c071\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">Additionally we\u2019ll pass in our\u00a0<code class=\"er jh ji jj jk b\">0&lt;=&gt;1<\/code>\u00a0animated value into scale so it will be moving and growing at the same time.<\/p>\n<pre class=\"ja jb jc jd ft jl jk jm bn jn jo bi\"><span id=\"89af\" class=\"jp jq he jk b be jr js l jt ju\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">const<\/span> reloadInterpolate = animation.<span class=\"hljs-title.function\">interpolate<\/span>({\r\n  <span class=\"hljs-attr\">inputRange<\/span>: [<span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">1<\/span>],\r\n  <span class=\"hljs-attr\">outputRange<\/span>: [<span class=\"hljs-number\">0<\/span>, -<span class=\"hljs-number\">70<\/span>],\r\n});\r\n \r\n<span class=\"hljs-keyword\">const<\/span> orderInterpolate = animation.<span class=\"hljs-title.function\">interpolate<\/span>({\r\n  <span class=\"hljs-attr\">inputRange<\/span>: [<span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">1<\/span>],\r\n  <span class=\"hljs-attr\">outputRange<\/span>: [<span class=\"hljs-number\">0<\/span>, -<span class=\"hljs-number\">140<\/span>],\r\n});\r\n \r\n<span class=\"hljs-keyword\">const<\/span> reloadStyle = {\r\n  <span class=\"hljs-attr\">transform<\/span>: [\r\n    {\r\n        <span class=\"hljs-attr\">scale<\/span>: animation\r\n    },\r\n    {\r\n      <span class=\"hljs-attr\">translateY<\/span>: reloadInterpolate,\r\n    },\r\n  ],\r\n};\r\n \r\n<span class=\"hljs-keyword\">const<\/span> orderStyle = {\r\n  <span class=\"hljs-attr\">transform<\/span>: [\r\n    {\r\n        <span class=\"hljs-attr\">scale<\/span>: animation\r\n    },\r\n    {\r\n      <span class=\"hljs-attr\">translateY<\/span>: orderInterpolate,\r\n    },\r\n  ],\r\n};<\/span><\/pre>\n<p id=\"0c2d\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\"><strong class=\"id hf\">Animate Labels<\/strong><\/p>\n<p id=\"0edf\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">The label animations are the more difficult of the animations. They start hidden in the center of each individual button. However, we don\u2019t want the text to appear over our icons and transition out. This would look bad.<\/p>\n<p id=\"0748\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">However, what we can do is keep it hidden and keep animating its location. Then once we know it\u2019s cleared the buttons of any overlap, we\u2019ll fade it in. The text will always be offset by <code class=\"er jh ji jj jk b\">-30<\/code>\u00a0and animate to an offset of\u00a0<code class=\"er jh ji jj jk b\">-90<\/code>\u00a0but to accomplish our fade in we&#8217;ll have it happen after our animation is\u00a0<code class=\"er jh ji jj jk b\">80%<\/code> complete. So we&#8217;ll make a cliff at that point and then quickly fade it into\u00a0<code class=\"er jh ji jj jk b\">1<\/code>\u00a0over the last\u00a0<code class=\"er jh ji jj jk b\">20%<\/code>\u00a0of the animation.<\/p>\n<p id=\"a244\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">We also want all of our labels to do the same thing so we can pass the same label style into all of our labels.<\/p>\n<pre class=\"ja jb jc jd ft jl jk jm bn jn jo bi\"><span id=\"82a7\" class=\"jp jq he jk b be jr js l jt ju\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">const<\/span> labelPositionInterpolate = animation.<span class=\"hljs-title.function\">interpolate<\/span>({\r\n  <span class=\"hljs-attr\">inputRange<\/span>: [<span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">1<\/span>],\r\n  <span class=\"hljs-attr\">outputRange<\/span>: [-<span class=\"hljs-number\">30<\/span>, -<span class=\"hljs-number\">90<\/span>],\r\n});\r\n \r\n<span class=\"hljs-keyword\">const<\/span> opacityInterpolate = animation.<span class=\"hljs-title.function\">interpolate<\/span>({\r\n  <span class=\"hljs-attr\">inputRange<\/span>: [<span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">0.8<\/span>, <span class=\"hljs-number\">1<\/span>],\r\n  <span class=\"hljs-attr\">outputRange<\/span>: [<span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">1<\/span>],\r\n});\r\n \r\n<span class=\"hljs-keyword\">const<\/span> labelStyle = {\r\n  <span class=\"hljs-attr\">opacity<\/span>: opacityInterpolate,\r\n  <span class=\"hljs-attr\">transform<\/span>: [\r\n    {\r\n      <span class=\"hljs-attr\">translateX<\/span>: labelPositionInterpolate,\r\n    },\r\n  ],\r\n};<\/span><\/pre>\n<p id=\"958a\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\"><strong class=\"id hf\">Animate Background<\/strong><\/p>\n<p id=\"9a12\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">Finally, our animated background is simply a scale of our small box. This is an arbitrary number selected, however, you could use math to calculate how many times the background needs to scale before it covers the entire view. I picked a large enough number to cover the screen and then some.<\/p>\n<pre class=\"ja jb jc jd ft jl jk jm bn jn jo bi\"><span id=\"0013\" class=\"jp jq he jk b be jr js l jt ju\" data-selectable-paragraph=\"\"><span class=\"hljs-keyword\">const<\/span> scaleInterpolate = animation.<span class=\"hljs-title.function\">interpolate<\/span>({\r\n  <span class=\"hljs-attr\">inputRange<\/span>: [<span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">1<\/span>],\r\n  <span class=\"hljs-attr\">outputRange<\/span>: [<span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">30<\/span>],\r\n});\r\n \r\n<span class=\"hljs-keyword\">const<\/span> bgStyle = {\r\n  <span class=\"hljs-attr\">transform<\/span>: [\r\n    {\r\n      <span class=\"hljs-attr\">scale<\/span>: scaleInterpolate,\r\n    },\r\n  ],\r\n};<\/span><\/pre>\n<p id=\"094a\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">You can download the code from this GitHub link <a class=\"ae ke\" href=\"https:\/\/github.com\/amanmanhas\/FloatingActionButton\/blob\/main\/App.tsx\" target=\"_blank\" rel=\"noopener ugc nofollow\">https:\/\/github.com\/amanmanhas\/FloatingActionButton\/blob\/main\/App.tsx<\/a><\/p>\n<p id=\"d082\" class=\"pw-post-body-paragraph ib ic he id b ie if ig ih ii ij ik il im in io ip iq ir is it iu iv iw ix iy gx bi\" data-selectable-paragraph=\"\">Thanks for reading this blog<\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Intro We\u2019ll be rebuilding the starbucks app pay button. Not only does this have a floating button, it has 2 other floating buttons, and a circular background cover that shoots out to allow you to focus on the options. These other 2 floating buttons will appear when user will press the floating pay button with [&hellip;]<\/p>\n","protected":false},"author":1568,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":30},"categories":[4687,1994],"tags":[5154,55,3505,5153],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56995"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1568"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=56995"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56995\/revisions"}],"predecessor-version":[{"id":57047,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56995\/revisions\/57047"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=56995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=56995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=56995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}