<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fabricio Bertani on Medium]]></title>
        <description><![CDATA[Stories by Fabricio Bertani on Medium]]></description>
        <link>https://medium.com/@fabricio-bertani?source=rss-e6e92e172a08------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LTlUjVYRxRibcVVZflEbvA.png</url>
            <title>Stories by Fabricio Bertani on Medium</title>
            <link>https://medium.com/@fabricio-bertani?source=rss-e6e92e172a08------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 23:44:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fabricio-bertani/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Animaciones de transición geniales con Shapes en Xamarin.Forms]]></title>
            <link>https://fabricio-bertani.medium.com/animaciones-de-transici%C3%B3n-geniales-con-shapes-en-xamarin-forms-b2288254b7eb?source=rss-e6e92e172a08------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2288254b7eb</guid>
            <category><![CDATA[xamarin-app-development]]></category>
            <category><![CDATA[xamarin]]></category>
            <category><![CDATA[xamarin-development]]></category>
            <category><![CDATA[xamarin-forms]]></category>
            <category><![CDATA[transitions]]></category>
            <dc:creator><![CDATA[Fabricio Bertani]]></dc:creator>
            <pubDate>Wed, 09 Jun 2021 13:15:19 GMT</pubDate>
            <atom:updated>2021-06-09T13:15:19.273Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I79dJXz1FKG2MO1e_cc1Iw.jpeg" /></figure><p>If you prefer to read this article in English, please follow this <a href="https://medium.com/geekculture/cool-transition-animations-with-shapes-in-xamarin-forms-7675e4ad0868">link</a>.</p><p>La versión oficial de Xamarin.Forms 4.7, incluyó por primera vez el control <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/">Shapes</a>, bajo bandera experimental. Volviendo rápidamente al presente, en la versión actual (<em>v5.0.0.2012</em>), las cosas han cambiado mucho, <em>Shapes </em>dejó atrás la bandera experimental, y ahora es bastante estable en todas las plataformas soportadas (Android, iOS, UWP, WPF y macOS).</p><p><em>Shapes </em>es un control muy poderoso, que nos permite dibujar fácilmente cualquier forma en la pantalla, como ser <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/ellipse">círculos</a>, <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/line">líneas</a>, <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/rectangle">rectángulos</a>, <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/polygon">polígonos</a> e incluso tomar valores de algún archivo de imagen svg y pegarlo en nuestra aplicación utilizando los <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/path">paths</a>.<br>Podemos utilizar este control para crear gráficos, fondos atractivos, controles de UI innovadores, etc., como se puede ver en <a href="https://devblogs.microsoft.com/xamarin/xamarin-forms-shapes-and-paths/">este gran artículo</a> de <strong>David Ortinau</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*LkY1y9a3bOxucKUS82opMg.jpeg" /><figcaption>Ejemplos de IU creadas con Shapes</figcaption></figure><p>Otra de las herramientas más potentes de Xamarin.Forms son las <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/animation/">Animaciones</a>, que nos ayudan a dar vida a nuestra aplicación utilizando los controles predeterminados o creando nuestras propias animaciones personalizadas.</p><h3>¡Animando Shapes!</h3><p>Para que nuestra aplicación se destaque por encima de las otras, debemos crear algo realmente impresionante y juntar <em>Shapes</em> con <em>animaciones</em> parece ser un buen comienzo. Además, vamos a añadir a la mezcla, navegación entre páginas.</p><p>Seamos honestos, las animaciones de transición incorporadas en Xamarin.Forms son bastante aburridas y el plugin <a href="https://github.com/GiampaoloGabba/Xamarin.Plugin.SharedTransitions">SharedTransitions</a> creado por <strong>Giampaolo Gabba</strong> está muy bueno, pero solo contiene transiciones comunes, ampliamente utilizadas hoy en día en la mayoría de las aplicaciones.<br>¡Por eso vamos a crear algunas animaciones de transición impresionantes utilizando <em>Shapes</em>!</p><p>Antes de comenzar, algunas consideraciones para esta publicación:</p><ul><li>A pesar de que Shapes está disponible para UWP, WPF y macOS, <em>nos atendremos únicamente</em> a iOS y Android.</li><li>Centralizaremos la mayoría de las navegaciones en el MainPage.</li><li>Eliminaremos la toolbar original y la reemplazaremos por una falsa, para poder presentar las animaciones en pantalla completa.</li><li>Estos son solo ejemplos, no un código de producción real.</li></ul><h4>¡Empecemos!</h4><p>Para todas nuestras páginas utilizaremos un control <em>Grid</em>, para envolver todo el contenido de la página, con el fin de aprovechar la propiedad de superposición de controles.<br>También le estableceremos un x:Name a la toolbar y al contenido para hacerlos desaparecer durante la transición.</p><p>Ahora vamos a crear nuestro primer shape, en este caso queremos una gran flecha roja apuntando a la derecha.</p><p>Para eso, vamos a utilizar un control <em>Path</em>. Al comprobar la <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/path-markup-syntax">sintaxis</a> podemos ver que el campo Data básicamente necesita: M para determinar el inicio del Path, junto a los puntos X,Y iniciales, luego con L definimos la línea y los diversos puntos X,Y que esta recorre para finalmente señalar el final del path usando Z.<br>Lo hacemos invisible y lo ocultamos en la parte izquierda de la pantalla.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02c1f1be2826326f1f54b4587b310b37/href">https://medium.com/media/02c1f1be2826326f1f54b4587b310b37/href</a></iframe><p>En el handler del botón de nuestro code behind, simplemente llamamos a un método asíncrono en el main thread que ejecutará nuestra <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/animation/custom">animación personalizada</a>.<br>En la animación, activaremos la visibilidad del shape y haremos que se mueva de izquierda a derecha, mientras desvanecemos la toolbar y el contenido. Toda esta animación durará 350 milisegundos.<br>Como nuestra animación se ejecuta de forma sincrónica, necesitamos añadir un delay un poco más largo que la animación y finalmente ejecutar la navegación a la siguiente página.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3d7c21cd55aaee7a4f5fba271cd2376/href">https://medium.com/media/a3d7c21cd55aaee7a4f5fba271cd2376/href</a></iframe><p>Comprobemos el resultado:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*9qWjOxglIv84HyobwZBlvw.gif" /><figcaption>Animación de transición en forma de flecha de izquierda a derecha</figcaption></figure><p>Nuestra <em>ArrowNavigationPage</em> será casi la misma que la <em>MainPage</em>, pero la flecha apuntará a la dirección opuesta.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f380ade3760c33cb86f22b7e2c55452/href">https://medium.com/media/4f380ade3760c33cb86f22b7e2c55452/href</a></iframe><p>El code behind será casi el mismo, pero también añadirá un override para el back button de Android.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e799362d6d756b45aeb2fb79006349ee/href">https://medium.com/media/e799362d6d756b45aeb2fb79006349ee/href</a></iframe><p>Y este será el resultado de la navegación hacia adelante y hacia atrás.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*w8KofpcVpOCgtTmVYi7JIg.gif" /><figcaption>Animación de la transición de izquierda a derecha y al revés</figcaption></figure><p>Para la transición de navegación a la segunda página, creemos shapes superpuestas.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44cbf62584d897099b5be9301c98b0fb/href">https://medium.com/media/44cbf62584d897099b5be9301c98b0fb/href</a></iframe><p>Y haremos que se mueva de abajo hacia arriba</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23aaf1089e2908faa7fc8d63b41066c2/href">https://medium.com/media/23aaf1089e2908faa7fc8d63b41066c2/href</a></iframe><p>El resultado:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*lZjMFcZ5_m0RRMJjBHyloA.gif" /><figcaption>Animación de transición de shapes superpuestos de abajo hacia arriba</figcaption></figure><p>Ahora, para la animación de retorno nos pondremos un poco más creativos y creemos dos círculos usando la forma <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/ellipse">Ellipse</a>, uno en la esquina superior izquierda de nuestra pantalla y el otro en la parte inferior derecha.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9024ecd9234bbfa3108214a454c7d75/href">https://medium.com/media/f9024ecd9234bbfa3108214a454c7d75/href</a></iframe><p>Haremos crecer un círculo desde la parte inferior derecha para volver a su tamaño original en la parte superior izquierda.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/739de63290d21bca57c5ee28d645ce79/href">https://medium.com/media/739de63290d21bca57c5ee28d645ce79/href</a></iframe><p>El resultado:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*yxylmdU4hCojcv3nB5pGyg.gif" /><figcaption>Animación de transición usando los shapes circulares</figcaption></figure><p>Continuando con nuestro “impulso creativo”, vamos a crear una animación de transición multipágina, es decir, una animación que comienza en una pantalla y termina en la otra.</p><p>Por eso, en Main Page añadimos algunos shapes ocultos a ambos lados de la pantalla.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3245f1960b1ec877073112489a994374/href">https://medium.com/media/3245f1960b1ec877073112489a994374/href</a></iframe><p>En el code behind, crearemos una animación que cierra los shapes de panel que hicimos y navegamos hacia la página siguiente.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f68ade0abd56efb1e3206609191bec0/href">https://medium.com/media/2f68ade0abd56efb1e3206609191bec0/href</a></iframe><p>En la siguiente página, iniciaremos con los mismos shapes de paneles, pero estos comenzarán cerrados.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11d359d2ec258e0b396a5f31f3082a80/href">https://medium.com/media/11d359d2ec258e0b396a5f31f3082a80/href</a></iframe><p>En el code behind, hacemos un override del método OnAppearing y ejecutamos la animación de apertura de los paneles.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85bff7352d84807bba1c6765418c6a84/href">https://medium.com/media/85bff7352d84807bba1c6765418c6a84/href</a></iframe><p>El resultado:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*okJLlC5iJR8euR1wakV5CQ.gif" /><figcaption>Animación de transición de los shapes izquierdo y derecho</figcaption></figure><p>Para la animación de regreso, hagamos algo aún más interesante.</p><p>Aunque algunos shapes son sencillos de hacer con paths, otros no lo son tanto o requerirían mucho tiempo para hacerlos, así que usaremos los <em>path data</em> de las imágenes SVG para eso.<br>Si tienen la suerte de contar con un diseñador/a de UI en su equipo, podrían pedirle que haga grandes diseños para utilizar en la app.<br>Caso contrario, pueden utilizar alguna herramienta como <a href="https://www.figma.com/">Figma</a> para crear y exportar el código SVG:</p><p>Primero, crearemos el shape en Figma, luego hacemos click con el botón derecho del ratón sobre ella, busca la sección <em>Copy/Paste</em> y seleccionamos Copy as SVG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*CV5tWR1vct4IfORKc2xAfg.jpeg" /></figure><p>Lo pegamos en nuestro editor favorito o visual studio y copiaremos el contenido dentro de la etiqueta d</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*47FHaUoQjLZ-gO3he9WmLQ.jpeg" /></figure><p>Finalmente, lo pegaremos como Data en un path de Xamarin.Forms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*fu6SMWU7cAumTlu1_rL8dw.jpeg" /></figure><p>Ahora vamos a añadir todos los shapes en nuestra pantalla:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc66bff354b23a46e541a3f8958c5f74/href">https://medium.com/media/fc66bff354b23a46e541a3f8958c5f74/href</a></iframe><p>Recordemos que debemos agregar lo mismo en el Main Page, pero también que solo queremos activar esa animación cuando regresemos de una página específica, por lo que simplemente agregamos una bandera:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e7b709f9eaeb8bca1e26aebd7da1832/href">https://medium.com/media/2e7b709f9eaeb8bca1e26aebd7da1832/href</a></iframe><p>Ahora podemos añadir el resto del código en el code behind de <em>PadlockTransitionAnimationShapes</em> para la animación de retorno.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5ca2244edafaf5695872bc3ef791249/href">https://medium.com/media/b5ca2244edafaf5695872bc3ef791249/href</a></iframe><p>El resultado:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*b--Jx67zSMv-Ia1F1KhAOA.gif" /><figcaption>Animación de transición del shape del candado</figcaption></figure><p>Para nuestro último ejemplo, vamos a estresar el motor con muchos shapes y animaciones corriendo al mismo tiempo en la pantalla. ¡Para ello haremos aparecer un pokemon salvaje como animación de transición!</p><p>Para este ejemplo añadiremos el pokemon como una imagen <em>png</em>, pero pueden buscar alguna imagen pokemon en formato svg para tomar el path 😉</p><p>Esta será nuestro shape en el Main Page</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/972941c4bbdfcf88965a46eee67247d4/href">https://medium.com/media/972941c4bbdfcf88965a46eee67247d4/href</a></iframe><p>Y la animación del code behind:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3847fc0f2ca060f52c15736fb6fb5f8c/href">https://medium.com/media/3847fc0f2ca060f52c15736fb6fb5f8c/href</a></iframe><p>El resultado:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*Jxc-0i34HpJIQX0qBfRgMA.gif" /><figcaption>Animación de transición para el shape de Pokemon</figcaption></figure><h4>Eso es todo amigos!</h4><p>Como dije anteriormente, estos son solo ejemplos de cómo podemos explotar nuestra creatividad y ampliar los límites de Xamarin.Forms.</p><p>Si esta publicación los ayuda a crear increíbles animaciones de transición o quieren mostrar las cosas que han hecho, por favor, dejar un repo de muestra en los comentarios y se añadirá a la publicación más adelante.</p><p>También pueden ver mi repositorio de ejemplo completo para esta publicación en GitHub. 👇</p><p><a href="https://github.com/FabriBertani/XFShapeAnimatedTransitions">FabriBertani/XFShapeAnimatedTransitions</a></p><p>Gracias por leer y a seguir codeando! 😁</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2288254b7eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cool transition animations with Shapes in Xamarin.Forms]]></title>
            <link>https://medium.com/geekculture/cool-transition-animations-with-shapes-in-xamarin-forms-7675e4ad0868?source=rss-e6e92e172a08------2</link>
            <guid isPermaLink="false">https://medium.com/p/7675e4ad0868</guid>
            <category><![CDATA[xamarin-development]]></category>
            <category><![CDATA[xamarin-forms]]></category>
            <category><![CDATA[xamarin-app-development]]></category>
            <category><![CDATA[transition-animations]]></category>
            <category><![CDATA[xamarin]]></category>
            <dc:creator><![CDATA[Fabricio Bertani]]></dc:creator>
            <pubDate>Wed, 09 Jun 2021 08:32:35 GMT</pubDate>
            <atom:updated>2021-06-09T13:17:25.760Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Smj8Id_pMGXoJLEWhN2fFg.jpeg" /></figure><p>If you prefer to read this article in Spanish, please follow this <a href="https://fabricio-bertani.medium.com/animaciones-de-transici%C3%B3n-geniales-con-shapes-en-xamarin-forms-b2288254b7eb">link</a>.</p><p>The official release of Xamarin.Forms 4.7, included for the first time the <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/"><strong><em>Shapes</em></strong></a> control, under the <em>experimental</em> flag. Fast-forward to the present, in the actual version (<em>v5.0.0.2012</em>), things change a lot, <em>Shapes</em> left behind the experimental flag, and now it’s pretty stable on all supported platforms (Android, iOS, UWP, WPF and macOS).</p><p><em>Shapes</em> it’s a really powerful control that allow us to easily draw any shape on screen, like <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/ellipse">circles</a>, <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/line">lines</a>, <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/rectangle">rectangles</a>, <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/polygon">polygons</a> and even take values from some svg image file and paste it by using the <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/path">paths</a>.<br>We could use this control to create graphics, good-looking backgrounds, innovative UI controls, etc., as can be seen on <a href="https://devblogs.microsoft.com/xamarin/xamarin-forms-shapes-and-paths/">this great article</a> by <strong>David Ortinau</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*LkY1y9a3bOxucKUS82opMg.jpeg" /><figcaption>UI samples created with Shapes</figcaption></figure><p>Another really powerful tool provided by Xamarin.Forms are <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/animation/">Animations</a>, that help us to bring life to our application by using default controls or create our own custom animations.</p><h3>Animating shapes!</h3><p>In order to make our application outstand the others, we should create something really impressive, and putting shapes with animations together seems like a good start. Also, let’s add navigation between pages into the mix.</p><p>Let’s face it, Xamarin.Forms built-in transition animation it’s boring and the <a href="https://github.com/GiampaoloGabba/Xamarin.Plugin.SharedTransitions">SharedTransitions</a> plugin created by <strong>Giampaolo Gabba </strong>it’s really neat, but it just contains common transitions widely used nowadays in most applications.<br>We are going to create some awesome transition animations using shapes!</p><p>Before starting, some considerations for this post:</p><ul><li>Despite Shapes being available for UWP, WPF and macOS, <em>we will stick to Android and iOS only</em>.</li><li>We are going to centralize most of the navigations on the MainPage.</li><li>We will remove the original toolbar and replace it with a fake one, in order to present the animations on full screen.</li><li>These are just samples, not actual production code.</li></ul><h4>Let’s get started!</h4><p>For all our pages we will use a <em>Grid </em>control to wrap the entire page content, in order to take advantage of the overlap property.<br>Also, we will set x:Name to the toolbar and content to make them disappear during the transition.</p><p>Here we are going to create our first shape, in this case, we want a big red arrow pointing to the right.<br>Let’s use a <em>Path </em>control. While checking the <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/path-markup-syntax">markup syntax</a> we can see that Data field basically needs: M to determine the start of the Path, next to the starting X,Y points, then with L we define the line and the several X,Y points that it travels and finally Z to signal the end of the path.<br>We make it invisible and hide it on the left side of the screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02c1f1be2826326f1f54b4587b310b37/href">https://medium.com/media/02c1f1be2826326f1f54b4587b310b37/href</a></iframe><p>In the button click handler of our code behind, we just call an async method on the main thread that will run our <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/animation/custom">custom animation</a>.<br>In the animation, we will turn the shape’s visibility on and make it move from left to right, while we fade off our toolbar and content. This whole animation will last 350 milliseconds.<br>As our animation is committed synchronously, we need to add a delay a bit longer than the animation and then finally run the navigation to the next page.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3d7c21cd55aaee7a4f5fba271cd2376/href">https://medium.com/media/a3d7c21cd55aaee7a4f5fba271cd2376/href</a></iframe><p>Let’s check the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*9qWjOxglIv84HyobwZBlvw.gif" /><figcaption>Left to right arrow shape transition animation</figcaption></figure><p>Our <em>ArrowNavigationPage </em>will be almost the same as the <em>MainPage</em>, but<em> </em>the arrow will be pointing in the opposite direction.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f380ade3760c33cb86f22b7e2c55452/href">https://medium.com/media/4f380ade3760c33cb86f22b7e2c55452/href</a></iframe><p>And code behind will be almost the same, but also add an override for the Android back button.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e799362d6d756b45aeb2fb79006349ee/href">https://medium.com/media/e799362d6d756b45aeb2fb79006349ee/href</a></iframe><p>And this will be the result of the forward and backward navigation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*w8KofpcVpOCgtTmVYi7JIg.gif" /><figcaption>Animation of transition from left to right and backwards</figcaption></figure><p>For our second page navigation transition, let’s create some overlapping shapes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44cbf62584d897099b5be9301c98b0fb/href">https://medium.com/media/44cbf62584d897099b5be9301c98b0fb/href</a></iframe><p>And let’s make it move from bottom to top</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23aaf1089e2908faa7fc8d63b41066c2/href">https://medium.com/media/23aaf1089e2908faa7fc8d63b41066c2/href</a></iframe><p>The result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*lZjMFcZ5_m0RRMJjBHyloA.gif" /><figcaption>Bottom to top arrow shape transition animation</figcaption></figure><p>Now, for the return animation, let’s get a little more creative and create two circles using the <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/shapes/ellipse">Ellipse</a>, one at the left top corner of our screen and the other at the right bottom.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9024ecd9234bbfa3108214a454c7d75/href">https://medium.com/media/f9024ecd9234bbfa3108214a454c7d75/href</a></iframe><p>We will grow a circle from the bottom right to return to its original size at the top left</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/739de63290d21bca57c5ee28d645ce79/href">https://medium.com/media/739de63290d21bca57c5ee28d645ce79/href</a></iframe><p>The result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*yxylmdU4hCojcv3nB5pGyg.gif" /><figcaption>Circle shape transition animation</figcaption></figure><p>Continuing with our “creative rush”, let’s create a multi-page transition animation, that’s mean an animation that starts on one screen and finish on the other one.</p><p>For that reason, on the Main Page we add some shapes hidden on both sides of the screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3245f1960b1ec877073112489a994374/href">https://medium.com/media/3245f1960b1ec877073112489a994374/href</a></iframe><p>In the code behind, we will create an animation that closes the pane shapes we made and navigate the next page.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f68ade0abd56efb1e3206609191bec0/href">https://medium.com/media/2f68ade0abd56efb1e3206609191bec0/href</a></iframe><p>On the next page, we start with the same panes shapes, but they must start closed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11d359d2ec258e0b396a5f31f3082a80/href">https://medium.com/media/11d359d2ec258e0b396a5f31f3082a80/href</a></iframe><p>In the code behind, we override the OnAppearing method and execute the panes open animation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85bff7352d84807bba1c6765418c6a84/href">https://medium.com/media/85bff7352d84807bba1c6765418c6a84/href</a></iframe><p>The result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*okJLlC5iJR8euR1wakV5CQ.gif" /><figcaption>Left and right pane shapes transition animation</figcaption></figure><p>For the return animation, let’s make something more interesting.</p><p>Although some shapes are simple to make with paths, others won’t or would require much time to make, so we will use SVG path data for that.<br>If you are lucky enough, maybe you have a UI designer on your team, you could go and ask them to make great designs that you can use.<br>If not, you can use some tool like <a href="https://www.figma.com/">Figma</a> to create and export SVG code:</p><p>Create your shape on Figma, then right-click on it, look for the <em>Copy/Paste </em>section and select Copy as SVG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*CV5tWR1vct4IfORKc2xAfg.jpeg" /></figure><p>Paste it on your editor and take the content inside the d tag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*47FHaUoQjLZ-gO3he9WmLQ.jpeg" /></figure><p>Finally, paste it as Data in a Xamarin.Forms path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*fu6SMWU7cAumTlu1_rL8dw.jpeg" /></figure><p>Now let’s add all the shapes to our screen:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc66bff354b23a46e541a3f8958c5f74/href">https://medium.com/media/fc66bff354b23a46e541a3f8958c5f74/href</a></iframe><p>Remember that we need to add the same on the Main Page, but also need to say that we only want to fire that animation when return from a specific page, so we simply add a flag:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e7b709f9eaeb8bca1e26aebd7da1832/href">https://medium.com/media/2e7b709f9eaeb8bca1e26aebd7da1832/href</a></iframe><p>Now we can add the rest of the code <em>PadlockTransitionAnimationShapes </em>code behind for the return animation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5ca2244edafaf5695872bc3ef791249/href">https://medium.com/media/b5ca2244edafaf5695872bc3ef791249/href</a></iframe><p>The result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*b--Jx67zSMv-Ia1F1KhAOA.gif" /><figcaption>Padlock shape transition animation</figcaption></figure><p>For our last example, let’s stress the engine with lots of shapes and animations running on the screen. For that reason, we will make a wild pokemon appear as transition animation!</p><p>For this example we add the pokemon as a png image, but you can look at some svg pokemon image to take the path 😉.</p><p>These will be our shapes on the MainPage</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/972941c4bbdfcf88965a46eee67247d4/href">https://medium.com/media/972941c4bbdfcf88965a46eee67247d4/href</a></iframe><p>And the code behind’s animation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3847fc0f2ca060f52c15736fb6fb5f8c/href">https://medium.com/media/3847fc0f2ca060f52c15736fb6fb5f8c/href</a></iframe><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*Jxc-0i34HpJIQX0qBfRgMA.gif" /><figcaption>Pokemon shapes transition animation</figcaption></figure><h4>That’s all folks!</h4><p>As I said before, these are just samples of how we can exploit our creativity and push the boundaries of Xamarin.Forms.</p><p>If this post helps you to create amazing transition animations or you want to showcase the things you’ve done, please leave a sample repo in the comments and will be added to this post later.</p><p>Also, you can see a complete sample repository for this post on GitHub. 👇</p><p><a href="https://github.com/FabriBertani/XFShapeAnimatedTransitions">FabriBertani/XFShapeAnimatedTransitions</a></p><p>Thanks for reading and keep coding! 😁</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7675e4ad0868" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/cool-transition-animations-with-shapes-in-xamarin-forms-7675e4ad0868">Cool transition animations with Shapes in Xamarin.Forms</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Material Outlined Text Field with Xamarin.Forms]]></title>
            <link>https://medium.com/geekculture/create-a-material-outlined-text-field-with-xamarin-forms-3da5eabab22c?source=rss-e6e92e172a08------2</link>
            <guid isPermaLink="false">https://medium.com/p/3da5eabab22c</guid>
            <category><![CDATA[xamarin-development]]></category>
            <category><![CDATA[xamarin-app-development]]></category>
            <category><![CDATA[material-design]]></category>
            <category><![CDATA[xamarin]]></category>
            <category><![CDATA[xamarin-forms]]></category>
            <dc:creator><![CDATA[Fabricio Bertani]]></dc:creator>
            <pubDate>Thu, 27 May 2021 10:47:42 GMT</pubDate>
            <atom:updated>2021-06-07T07:32:08.522Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*fJeF0xUTiGF--EECL7jRbA.jpeg" /></figure><p>If you prefer to read this article in Spanish, please follow this <a href="https://fabricio-bertani.medium.com/crear-un-material-outlined-text-field-con-xamarin-forms-93044e42042c">link</a></p><p>Sometime ago, the Xamarin team officially release <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/visual/material-visual">Material Visual</a>, a feature to change the UI controls of your application in order to follow the <a href="https://material.io/design">Material Design Rules</a> proposed by Google. <br>This is an amazing feature, as you can check on the official docs and <a href="https://devblogs.microsoft.com/xamarin/visual-challenge-conquered/">other several posts about using it</a>. They are built natively on each platform and have a great performance, but…(there is always a but), they just add the standard material UI elements, leaving aside other elements, like the <a href="https://material.io/components/text-fields#">outlined text field</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*FmvKdygeyM7VEJENGd0shw.png" /><figcaption>Material outlined text field sample on the Material docs.</figcaption></figure><h4>For that reason, today we are going to create a material outlined textfield entirely on Xamarin.Forms!!!</h4><p>As I said before, the Material Visual feature built by Xamarin is completely native, for that reason it has better performance. We are going to have to sacrifice a bit of performance (nearly unnoticeable to the untrained eye) in order to write this control, <em>almost</em>, without having to deal with native code on each platform.</p><p>Before starting, let’s make a list of what our control should have:</p><ul><li>Rounded borders</li><li>Borders should change color</li><li>Placeholder animation</li><li>Character counter</li><li>Leading and trailing icons</li><li>Interactive icons for password</li><li>Helper and error texts</li><li>Error icon</li></ul><p>In order to see what we’re dealing with, we just build our app with a regular entry and a material one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nl9-G9toUFNHgXNeiHd-IA.png" /><figcaption>Regular and material entries on Android, iOS and UWP</figcaption></figure><p>Let’s focus on the regular entry:</p><ul><li>In UWP it has a frame that we need to get rid of.</li><li>In iOS also has a frame that needs to be removed.</li><li>In Android, we need to remove that annoying underline.</li></ul><p>So let’s create some effects for it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/925459287c24af098165ef52501357c2/href">https://medium.com/media/925459287c24af098165ef52501357c2/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26e492f536c47bccc81b2cf00b232087/href">https://medium.com/media/26e492f536c47bccc81b2cf00b232087/href</a></iframe><p>Great! Now we need to make from our outlined text field a reusable solution, so we should create a component of it.<br>We will use:</p><ul><li>A Grid that contains all, because of it overlay property will help us with the placeholder animation.</li><li>A Frame to wrap around the entry with rounded borders and border color.</li><li>The other labels for helper, counter and error texts.</li><li>Images for the icons</li></ul><p><strong>Let’s create our reusable component!</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19a09240d85a8f63a4fdb86da58dd47b/href">https://medium.com/media/19a09240d85a8f63a4fdb86da58dd47b/href</a></iframe><p>And now on the code behind let’s define the bindable properties, event handlers, animations and methods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d4d9a944ce1e3d784e30cf8736dab5a/href">https://medium.com/media/3d4d9a944ce1e3d784e30cf8736dab5a/href</a></iframe><h4><strong>Let’s test it</strong></h4><p>Just add the new component into a Xamarin.Forms page to see the results:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93d7304635681e97e9248a6db4e78764/href">https://medium.com/media/93d7304635681e97e9248a6db4e78764/href</a></iframe><p>Now let’s see it running in all the 3 different supported platforms!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xq51epaZl_gvJFt-KylpRw.gif" /><figcaption>Our Material Outlined Entry running on Android, iOS and UWP!</figcaption></figure><h4><strong>That’s all for today folks</strong></h4><p>Hope this help you to create new cool components and explore the power of Xamarin.Forms controls.</p><p>Also, you can see a complete sample repository for this post on GitHub.</p><p><a href="https://github.com/FabriBertani/XFOutlinedMaterialEntry">FabriBertani/XFOutlinedMaterialEntry</a></p><p>Thanks for reading and keep coding! 😁</p><p><strong><em>Edit: </em></strong>It also could works on macOS, but needs some changes and adjustments, check the sample repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*uNnX4aEEHb7mer2NZtsuhQ.png" /><figcaption>Kinda running on macOS, need fixes and adjustments</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3da5eabab22c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/create-a-material-outlined-text-field-with-xamarin-forms-3da5eabab22c">Create a Material Outlined Text Field with Xamarin.Forms</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crear un Material Outlined Text Field con Xamarin.Forms]]></title>
            <link>https://fabricio-bertani.medium.com/crear-un-material-outlined-text-field-con-xamarin-forms-93044e42042c?source=rss-e6e92e172a08------2</link>
            <guid isPermaLink="false">https://medium.com/p/93044e42042c</guid>
            <category><![CDATA[xamarin-forms]]></category>
            <category><![CDATA[xamarin-development]]></category>
            <category><![CDATA[material-design]]></category>
            <category><![CDATA[xamarin-app-development]]></category>
            <category><![CDATA[xamarin]]></category>
            <dc:creator><![CDATA[Fabricio Bertani]]></dc:creator>
            <pubDate>Tue, 25 May 2021 14:54:14 GMT</pubDate>
            <atom:updated>2021-06-07T07:33:13.418Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*zVOzTIZ0WjTMFfbMKMIUQA.jpeg" /></figure><p>If you prefer to read this article in English, please follow this <a href="https://medium.com/geekculture/create-a-material-outlined-text-field-with-xamarin-forms-3da5eabab22c">link</a></p><p>Hace algún tiempo, el equipo de Xamarin lanzó oficialmente <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/visual/material-visual">Material Visual</a>, una característica que nos permite cambiar los controles de la UI de nuestra aplicación con el fin de seguir las <a href="https://material.io/design">reglas de diseño de Material</a> propuestas por Google.<br>Esta es una característica increíble, como se puede comprobar en los documentos oficiales y algunos <a href="https://devblogs.microsoft.com/xamarin/visual-challenge-conquered/">otros posts relacionados con el tema</a>. Los mismos están construidos de forma nativa en cada plataforma y tienen un gran rendimiento, pero… (siempre hay un pero), sólo añaden los elementos estándar de la UI de Material, dejando de lado algunos otros elementos, como el <a href="https://material.io/components/text-fields">outlined text field</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*dQujM376doeJvFN3shNNpw.png" /><figcaption>Ejemplo del outlined text field en los documentos de Material.</figcaption></figure><h4><strong>Por esa razón, hoy vamos a crear un Material outlined text field completamente en Xamarin.Forms !!!</strong></h4><p>Como dije anteriormente, la función Material Visual creada por Xamarin es completamente nativa, por esa razón tiene mejor rendimiento. En nuestro caso, vamos a tener que sacrificar un poco de rendimiento (casi imperceptible para el ojo inexperto) para poder escribir este control, <em>practicamente</em>, sin tener que lidiar con código nativo en cada plataforma.</p><p>Antes de comenzar, hagamos una lista de lo que debería tener nuestro control:</p><ul><li>Bordes redondeados</li><li>Los bordes deben cambiar de color</li><li>Animación de placeholder</li><li>Contador de caracteres</li><li>Iconos al comienzo y al final</li><li>Iconos interactivos para contraseñas</li><li>Textos de ayuda y de error</li><li>Icono de error</li></ul><p>Para ver con qué estamos lidiando, simplemente creamos nuestra aplicación con una eEntry común y corriente y uno del tipo material.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nl9-G9toUFNHgXNeiHd-IA.png" /><figcaption>Campos de texto comunes y material en Android, iOS y UWP</figcaption></figure><p>Vamos a enfocarnos en el Entry común:</p><ul><li>En UWP tiene un marco del que tendremos que deshacernos.</li><li>iOS a su vez tiene un marco que debe ser eliminado.</li><li>En Android tendremos que eliminar ese subrayado molesto.</li></ul><p>Así que vamos a crear algunos efectos para ello:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/925459287c24af098165ef52501357c2/href">https://medium.com/media/925459287c24af098165ef52501357c2/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26e492f536c47bccc81b2cf00b232087/href">https://medium.com/media/26e492f536c47bccc81b2cf00b232087/href</a></iframe><p>¡Muy bien! Ahora necesitaremos hacer de nuestro outlined text field una solución reutilizable, por lo que debemos crear un componente de ella.<br>Para ello utilizaremos:</p><ul><li>Un <em>Grid</em> que contenga todo el contenido y especialmente por su propiedad de superposición de controles, que nos ayudará con la animación del placeholder.</li><li>Un <em>Frame </em>para envolver el entry con bordes redondeados y de colores.</li><li>Los otras <em>Labels</em> para los textos de ayuda, contador y error.</li><li>Imágenes para los iconos.</li></ul><h4><strong>¡Creemos nuestro componente reutilizable!</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19a09240d85a8f63a4fdb86da58dd47b/href">https://medium.com/media/19a09240d85a8f63a4fdb86da58dd47b/href</a></iframe><p>Y ahora, en nuestro code behind, definiremos las bindable properties, los event handlers, las animaciones y los métodos.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d4d9a944ce1e3d784e30cf8736dab5a/href">https://medium.com/media/3d4d9a944ce1e3d784e30cf8736dab5a/href</a></iframe><h4><strong>Vamos a probarlo</strong></h4><p>Simplemente añadiremos el nuevo componente en una página de Xamarin.Forms para ver los resultados:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93d7304635681e97e9248a6db4e78764/href">https://medium.com/media/93d7304635681e97e9248a6db4e78764/href</a></iframe><p>Ahora veremos cómo se ejecuta en las tres plataformas disponibles!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xq51epaZl_gvJFt-KylpRw.gif" /><figcaption>Nuestro Material Outlined Entry corriendo en Android, iOS y UWP!</figcaption></figure><h4><strong>Eso es todo por hoy amigos!</strong></h4><p>Espero que esto los ayude a crear nuevos componentes geniales y a explorar la potencia de los controles de Xamarin.Forms.</p><p>También puede ver mi repositorio de ejemplo completo para esta publicación en GitHub.</p><p><a href="https://github.com/FabriBertani/XFOutlinedMaterialEntry">FabriBertani/XFOutlinedMaterialEntry</a></p><p>Gracias por leer y a seguir codeando! 😁</p><p><strong><em>Edit: </em></strong>también funciona a grandes rasgos en macOS, pero necesita algunos cambios y ajustes, revisen el repositorio de muestra.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*SP5u2jnB5f9R9QFXg3WPSw.png" /><figcaption>Prácticamente funciona en macOS, solo necesita algunos ajustes y arreglos.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93044e42042c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementando AiForms.Dialogs con Xamarin.Forms]]></title>
            <link>https://fabricio-bertani.medium.com/implementando-aiforms-dialogs-con-xamarin-forms-c700f5bf81aa?source=rss-e6e92e172a08------2</link>
            <guid isPermaLink="false">https://medium.com/p/c700f5bf81aa</guid>
            <category><![CDATA[loading]]></category>
            <category><![CDATA[alerts]]></category>
            <category><![CDATA[dialog]]></category>
            <category><![CDATA[toast]]></category>
            <category><![CDATA[xamarin-forms]]></category>
            <dc:creator><![CDATA[Fabricio Bertani]]></dc:creator>
            <pubDate>Wed, 09 Dec 2020 21:10:54 GMT</pubDate>
            <atom:updated>2020-12-09T21:10:54.828Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*JGl7FfqvPyyD4lQAMQGKlQ.png" /></figure><p>If you prefer to read this article in English, please follow this <a href="https://medium.com/@fabricio.bertani/implementing-aiforms-dialogs-with-xamarin-forms-60dc93903847">link</a></p><p><strong>Aviso</strong>: el propósito de esta publicación no es ofender ni insultar a ningún diseñador gráfico o UI/UX, sino burlarme un poco de mí mismo y de mi falta de habilidades de diseño.</p><p>Por lo general, trabajamos en equipos, a veces pequeños, otras veces en equipos grandes, pero casi todos los equipos tienen al menos un diseñador de UI/UX o alguien de parte del cliente proporciona el diseño de nuestros proyectos.<br>Ocasionalmente, los diseñadores se vuelven demasiado creativos y nos piden que hagamos algunos controles poco convencionales o algo aún más difícil, como algunos alertas personalizadas!!!</p><p>Echemos un vistazo a la imagen a continuación para apreciar el más increible diseño de un popup de alerta, si nuestra aplicación fuera como un sitio web de la década pasada…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*K1ZY7UFXLfYssHIMI7mufA.jpeg" /><figcaption>Un popup super creativo!</figcaption></figure><p>Como podemos ver, nuestro popup especial no encaja con la biblioteca de dialogs integrada de Xamarin.Forms.<br>Tampoco podemos lograr la tarea con la gran y ampliamente utilizada biblioteca <a href="https://github.com/aritchie/userdialogs">Acr.UserDialogs</a>.<br>Si seguimos buscando, podríamos encontrarnos con otro plugins muy popular, por supuesto que estoy hablando de <a href="https://github.com/rotorgames/Rg.Plugins.Popup">Rg.Plugins.Popup</a>. Aparentemente parece ser lo que necesitamos, pero como tenemos almas curiosas e inquietas, seguimos investigando un poco más, solo por si acaso, hasta que nos topamos con esta pequeña pero poderosa biblioteca llamada <a href="https://github.com/muak/AiForms.Dialogs">AiForms.Dialogs</a>.</p><p>La llamo pequeña, porque no es ampliamente conocida o utilizada como su contrincante, esta librería tiene casi 30 mil descargas en Nuget contra más de 2 millones de Rg.Plugins.Popup.</p><h3>Vamos a compararlas!</h3><h4>Rg.Plugins.Popup:</h4><ul><li>Te permite crear páginas de Xamarin.Forms y ejecutarlas como popup o alerts que se pueden ser compartidas en iOS, Android, UWP y macOS.</li><li>¡Proporciona animaciones geniales!</li><li>La implementación se basa puramente en Xamarin.Forms, solo usa renderers de vistas de Xamarin.Forms en el lado nativo.</li><li>Utiliza su propio sistema de navegación para ir hacia adelante y atrás en las páginas emergentes.</li><li>Fácil de implementar pruebas unitarias con él.</li></ul><h4>AiForms.Dialogs:</h4><ul><li>Te permite crear páginas de Xamarin.Forms e iniciarlas como un alert, un toast o un loading indicator, que se pueden compartirse en iOS y Android.</li><li>Te permite crear tus propias animaciones.</li><li>Las implementaciones son nativas (usando DialogFragment en Android y UIPresentationController en iOS, por ejemplo).</li><li>Incluye dialogs y loading reutilizables, esto significa que los métodos de dispose no se ejecutan para reutilizarlos durante el ciclo de vida de la página.</li><li>No es necesario utilizar ninguna navegación personalizada.</li></ul><p>Como podemos ver, <em>Rg.Plugins.Popup</em> podría ser una gran opción, principalmente porque admite una mayor gama de plataformas y pruebas unitarias, pero <em>AiForms.Dialogs</em> ofrece loadings y toast personalizables que incluso se basan en implementaciones nativas. ¡Nuestro loco diseñador estaría realmente feliz!</p><h3>Manos a la obra!</h3><p>Primero necesitamos instalar el paquete nuget <a href="https://www.nuget.org/packages/AiForms.Dialogs/">AiForms.Dialogs</a> en nuestros proyectos de Forms, Android e iOS.<br>Recuerda que debes inicializar el paquete en Android, después de la inicialización de Xamarin.Forms:</p><pre>AiForms.Dialogs.Dialogs.Init(this);</pre><p>Luego, en nuestro proyecto Xamarin.Forms, crearemos un ContentView normal, pero lo cambiaremos para que sea un DialogView y crearemos nuestra vista como siempre, no sin antes agregar algunas pequeñas propiedades adicionales a nuestro DialogView base:</p><ul><li>OverlayColor: el color de superposición de fondo para nuestro alert (el predeterminado es blanco o transparente).</li><li>UseCurrentPageLocation: de acuerdo con la documentación del plugin, esta propiedad booleana definirá si nuestro alert se alineará con los bordes de la ventana o con el área de la página actual. En nuestro caso lo configuraremos como falso.</li><li>IsCanceledOnTouchOutside: esta propiedad booleana simplemente definirá si el usuario puede cerrar el alert tocando el área fuera de ella. En nuestro caso lo configuraremos como falso.</li></ul><p><strong>Nota</strong>: Si setea la propiedad BorderColor, recuerda agregar un color de fondo al contenido de DialogView, de lo contrario, tomará BorderColor como BackgroundColor del contenido.</p><p>Entonces este será el XAML de nuestra alerta:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ec117123a6f0a361a55a252264fcabf/href">https://medium.com/media/0ec117123a6f0a361a55a252264fcabf/href</a></iframe><p>Y no te olvides de cambiar el tipo base de ContentView a DialogView en el code behind.<br>Tampoco te olvides de configurar correctamente el DialogNotifier para los botones de acción, estos son realmente importantes en caso de que estemos escuchando los eventos para saber qué opción elige el usuario.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ccccf963dc272b5e959d4ee3ec0157f/href">https://medium.com/media/4ccccf963dc272b5e959d4ee3ec0157f/href</a></iframe><p>Y por último necesitamos abrir el dialog llamando a la abstracción Dialog.Instance, pero no olvidemos que este es un método asíncrono y por lo tanto debemos usar la palabra clave await, así que podemos usar Device.BeginInvokeOnMainThread si no estamos dentro de un método de asíncrono.<br>El método ShowAsync&lt;TDialogView&gt;() devuelve una Task&lt;bool&gt; que se establece a través de los métodos DialogNotifier.Cancel() y DialogNotifier.Complete(), los cualespuede ser usados para ejecutar otras partes de nuestro código en cada respuesta.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc5088f73150c783161e6a4ba98b4152/href">https://medium.com/media/dc5088f73150c783161e6a4ba98b4152/href</a></iframe><p>Este es nuestro resultado en ambas plataformas:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*nml_52uLWpB2-F6PwtdTCA.jpeg" /><figcaption>¡Los sueños de nuestro diseñador loco se hacen realidad!</figcaption></figure><p>Mientras le contamos al diseñador acerca de las bondades que ofrece nuestra recientemente descubierta herramienta, él ya está pensando en su próxima loca solicitud…</p><p>Resulta ser que nuestro diseñador ama a Ryan Reynolds (¿quién no, verdad?). Por lo tanto, ahora nos solicita un loading a que contenga una cara animada de Reynolds, junto con una cita inspiradora, ¡así cumpliremos sus deseos!</p><p>Como hicimos anteriormente, crearemos otro ContentView, cambiaremos el tipo base a LoadingView esta vez, luego establezcamos OverlayColor en gris con transparencia y finalmente agreguemos nuestro contenido dentro de un StackLayout.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2f8d3bb445f2df4d95364abb85d3ea0/href">https://medium.com/media/b2f8d3bb445f2df4d95364abb85d3ea0/href</a></iframe><p>Cambiamos el tipo base a LoadingView en el code behind, luego crearemos la animación en el método constructor y la consumiremos con los métodos RunPresentationAnimation y RunDismissalAnimation proporcionados por el plugin para ejecutar y destruir la animación.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b158e180452719df9664d06311aa1435/href">https://medium.com/media/b158e180452719df9664d06311aa1435/href</a></iframe><p>¡Veamos el resultado final!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*1ez8wvVVhHkJbzVFayC9Ag.gif" /><figcaption>Nuestro diseñador loco y Ryan Reynolds estarían muy contentos con el resultado.</figcaption></figure><p>Ahora decidió que deberíamos darle advertencias a los usuarios mediante un toast utilizando la siguiente guía</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*81aha5P2Qu3n1Bcy93P9Kg.jpeg" /><figcaption>¿Más ComicSans?</figcaption></figure><p>Una vez más, crearemos un nuevo ContentView, cambiaremos el tipo base a ToastView y esta vez necesitamos establecer algunas propiedades:</p><ul><li>HorizontalLayoutAlignment: cómo se colocará horizontalmente. En nuestro caso lo configuramos en Fill.</li><li>VerticalLayoutAlignment: dónde se colocará el toast verticalmente. En nuestro caso, lo configuramos en End para colocarlo en la parte inferior de la pantalla.</li><li>OffsetY: si colocamos el toast en la parte superior o inferior de la pantalla, necesitaremos usar esta propiedad para ajustar la posición, especialmente con iOS porque no respetará el ajuste del SafeArea. En nuestro caso lo configuramos en -35.</li><li>Duration: expresada en milisegundos, esto determinará cuánto tiempo estará visible el toast en pantalla. En nuestro caso lo configuramos en 3000.</li></ul><p>Este será el XAML de nuestro toast:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80497b0cb93fd5eb89ff23852ac78226/href">https://medium.com/media/80497b0cb93fd5eb89ff23852ac78226/href</a></iframe><p>No olvidemos cambiar el tipo base a ToastView en el code behind. También recuerdemos que es posible agregarle animaciones.</p><p>¡Veamos el resultado final!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*m5BTD_da-oc5xSSohjgL0w.jpeg" /><figcaption>Un hermoso toast personalizado</figcaption></figure><p>A nuestro diseñador loco le gustó tanto el diseño del alert que quiere usarla para todos los que aparezcan en la aplicación.<br>Para realizar esta tarea y anticiparnos a una posible solicitud especial futura del mismo, creemos una clase helper que se pueda registrar como singleton, por lo que nos ayudará a usarla tanto desde nuestros views como desde nuestros viewmodels.</p><p>Definamos los métodos de nuestra interface</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e4f3ae6406517e424978a1189ac5c59/href">https://medium.com/media/3e4f3ae6406517e424978a1189ac5c59/href</a></iframe><p>Si lo desglosamos:</p><ul><li>Un método ShowAlert para mostrar nuestros alerts, con algunos parámetros requeridos y algunos parámetros opcionales, que devuelve un bool, el cual indica si el alert fue cancelado o aceptado.</li><li>Dos métodos ShowLoading, aprovechando la herencia de C#, definimos un método para loading regulares y otro que toma un parámetro para mostrar un mensaje mientras la vista de loading está visible.</li><li>Un método sencillo de HideLoading para ocultar nuestro loading.</li><li>Un método especial ShowLoadingWithProgressAsync para mostrar un conteo de progreso al cargar, por ejemplo, si queremos que los usuarios conozcan el progreso de la descarga de un archivo. Se necesita un Func&lt;IProgress&lt;double&gt;, Task&gt; como parámetro para pasarlo al loading y un texto para mostrar algún mensaje personalizado mientras el loading está visible.</li><li>DisplayToast nos ayudará a mostrar un simple toast, pasamos un mensaje y duración expresada en milisegundos, definimos una duración predeterminada de 3 segundos.</li></ul><p>Y ahora la implementación:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c81e53fa8bed893ee165866476ca225c/href">https://medium.com/media/c81e53fa8bed893ee165866476ca225c/href</a></iframe><p>Primero definimos la implementación de nuestro singleton para el helper.</p><p>Echemos un vistazo más de cerca a la implementación de ShowAlert:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/160f463bfca3397a704020873ecac7fa/href">https://medium.com/media/160f463bfca3397a704020873ecac7fa/href</a></iframe><p>Es casi lo mismo que nuestro WinMoneyDialogView, pero cambiamos los textos con algunos binding: DialogText, AcceptText y CancelText. Estos nombres pueden ser los que queramos, pero deben ser los mismos a la hora de crear la vista como podemos ver aquí:</p><pre>await Dialog.Instance.ShowAsync&lt;DefaultDialogView&gt;(new<br>{<br>    DialogText = dialogText,<br>    AcceptText = acceptText,<br>    CancelText = cancelText<br>});</pre><p>El plugin se encargará de convertir esos enlaces.</p><p>Ahora, si echamos un vistazo a la primera implementación de ShowLoading, simplemente llamamos a la implementación predeterminada del loading del plugin y establecemos un mensaje predeterminado.<br>En la segunda implementación, llamamos primero al método Show y luego al método SetMessage con nuestro mensaje personalizado.<br>HideLoading simplemente llamará al método Hide del plugin.</p><p>ShowLoadingWithProgressAsync, al igual que ShowAlert, será un método asíncrono, simplemente pasamos la función y el mensaje al método StartAsync, que toma la misma Func&lt;IProgress&lt;double&gt;, Task&gt; y el mensaje.</p><p>Finalmente, para el método DisplayToast, necesitamos crear una nueva vista de toast:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c56c1c75492035d1d46ea565ca1740cf/href">https://medium.com/media/c56c1c75492035d1d46ea565ca1740cf/href</a></iframe><p>Al igual que ShowAlert, necesitamos pasar el binding</p><pre>Toast.Instance.Show&lt;DefaultToastDialogView&gt;(new<br>{<br>    ToastText = toastText,<br>    Duration = duration<br>});</pre><h4>Hora de las pruebas</h4><p>Para probar nuestra implementación del helper, crearemos una vista y un viewmodel asociado a ella.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7649629dc16df2b5257e59bb99b341ab/href">https://medium.com/media/7649629dc16df2b5257e59bb99b341ab/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d45f8be4b9644b928fe2a5ae8026030/href">https://medium.com/media/6d45f8be4b9644b928fe2a5ae8026030/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1196670ddd148e3c116d144ef4bf2786/href">https://medium.com/media/1196670ddd148e3c116d144ef4bf2786/href</a></iframe><p>Añadimos los bindings a nuestro viewmodel y alguna implementación en el code behind para probar.</p><ul><li>OpenRegularLoading llama a nuestra instancia de nuestro DialogHelper y mostrará un loading durante 3 segundos.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*4ibrLPI0CSaOW-GOWZk5tA.gif" /><figcaption>Una vista de loading simple</figcaption></figure><ul><li>OpenLoadingWithCustomText tomará el texto del Entry y mostrará el loading con él.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*YEIF-JPKMZVL-Dla0V3A4A.gif" /><figcaption>Una vista de loading con texto personalizado</figcaption></figure><ul><li>OpenDialogWithCustomText esta fue la solicitud original de nuestro diseñador, le pasamos un mensaje personalizado y definimos “Yes”/“No” como opciones.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*p_FoOpThPsreUVz0-8wWPg.gif" /><figcaption>Nuestro alert especial ahora admite cualquier texto como mensaje</figcaption></figure><ul><li>OpenFakeDownloadLoading aquí simularemos una descarga para probar el progress.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*mkxr0qWQ6Vnr9J86XrIq5Q.gif" /><figcaption>Un loading con indicador de progreso</figcaption></figure><ul><li>OpenRegularToast_Clicked implementamos este método en el code behind de nuestro xaml para probar si nuestro helper también funciona allí. Le pasamos algún texto y la duración.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*cD5EYClxB6vhPx5mFJypbQ.gif" /><figcaption>Un toast normal que se muestra en el centro de la pantalla.</figcaption></figure><h4>Eso es todo amigos!</h4><p>Creo que este es un plugin realmente útil y te recomiendo que lo pruebes y, si te gusta, dejes una estrella en el repositorio porque Kamu (el creador) realmente se lo merece.</p><p>También puede ver mi repositorio de ejemplo completo para esta publicación en GitHub.</p><p><a href="https://github.com/FabriBertani/AiFormsDialogsXamarinForms">FabriBertani/AiFormsDialogsXamarinForms</a></p><p>Gracias por leer y a seguir codeando mientras Vincent Connare se ríe desde el infierno 😁</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c700f5bf81aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing AiForms.Dialogs with Xamarin Forms]]></title>
            <link>https://fabricio-bertani.medium.com/implementing-aiforms-dialogs-with-xamarin-forms-60dc93903847?source=rss-e6e92e172a08------2</link>
            <guid isPermaLink="false">https://medium.com/p/60dc93903847</guid>
            <category><![CDATA[alerts]]></category>
            <category><![CDATA[loading]]></category>
            <category><![CDATA[xamarin-forms]]></category>
            <category><![CDATA[toast]]></category>
            <category><![CDATA[dialog]]></category>
            <dc:creator><![CDATA[Fabricio Bertani]]></dc:creator>
            <pubDate>Wed, 09 Dec 2020 21:06:36 GMT</pubDate>
            <atom:updated>2020-12-09T21:12:11.932Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*2PanG77IWGdePrm5mA6YKw.png" /></figure><p>If you prefer to read this article in Spanish, please follow this <a href="https://medium.com/@fabricio.bertani/implementando-aiforms-dialogs-con-xamarin-forms-c700f5bf81aa">link</a></p><p><strong><em>Disclaimer</em></strong>: the purpose of this post is not to offend nor insult any graphic or UI/UX designer, but to make a little fun of myself and to my lack of design skills.</p><p>We usually work in teams, sometimes they are small, other times they are big, but almost every team have at least one UI/UX designer or someone from the client that provide design to our projects.<br>Occasionally designers get overly creative and ask us to do some unconventional controls or something even harder like some custom alert dialogs!!!</p><p>Let’s take a look to the image below to appreciate the most incredible popup alert design, if our application was like a website from last decade…</p><figure><img alt="Example of funny mobile app screen design" src="https://cdn-images-1.medium.com/max/800/1*K1ZY7UFXLfYssHIMI7mufA.jpeg" /><figcaption>A really creative alert!</figcaption></figure><p>As we can see, our special alert popup doesn’t fit with the Xamarin.Forms built-in dialogs library.<br>We can’t accomplishthe task with the great and widely used <a href="https://github.com/aritchie/userdialogs/tree/96423dc60bd32338dba625eb293aac3c75e876be">Acr.UserDialogs</a> library neither.<br>If we keep searching, we might come across with other popular plugin, of course I’m talking about <a href="https://github.com/rotorgames/Rg.Plugins.Popup">Rg.Plugins.Popup</a>. Apparently seems to be what we need for, but with our curious and restless souls, we keep researching a little more, just in case, until we run into this small but powerful library named <a href="https://github.com/muak/AiForms.Dialogs">AiForms.Dialogs</a>.</p><p>I call it small, because isn’t widely known/used as its contrincant, almost 30 thousand downloads on Nuget against over 2M from Rg.Plugins.Popup.</p><h3><strong>Let’s compare them!</strong></h3><h4><em>Rg.Plugins.Popup</em>:</h4><ul><li>Allows you to create Xamarin.Forms pages and launch them as popup that can be shared across iOS, Android, UWP, and macOS.</li><li>Provides cool animations!</li><li>The implementation lies only on Xamarin.Forms, only use page renderers on the native side.</li><li>Uses it’s own navigation system to push and pop the popup pages.</li><li>Easy to implement Unit Testing with it.</li></ul><h4>AiForms.Dialogs:</h4><ul><li>Allows you to create Xamarin.Forms pages and launch them as alert popup, toast or loading indicator, that can be shared across iOS and Android.</li><li>Allows you to create your own animations.</li><li>Implementations are native (using DialogFragment on Android and UIPresentationController on iOS for example).</li><li>Includes reusable dialog and loading, this means that dispose methods are not executed in order to reuse them during the page lifecycle.</li><li>No need to use any custom navigation.</li></ul><p>As we can see <em>Rg.Plugins.Popup</em> could be a great option, mostly because it support a much greater range of platforms and Unit Testing, but <em>AiForms.Dialogs </em>offers loadings and toast customizable views that even relay on native implementations. Our crazy designer would be really happy!</p><h3>Let’s get down to work!</h3><p>First we need to install the <a href="https://www.nuget.org/packages/AiForms.Dialogs/">AiForms.Dialogs</a> nuget package in our Forms, Android and iOS projects.<br>Remember that you need to initialize the package on Android, after the Xamarin.Forms initialization:</p><pre>AiForms.Dialogs.Dialogs.Init(this);</pre><p>Then on our Xamarin.Forms project lets create a regular ContentView, but change it to be a DialogView and create our view as usual but add some small extra properties to our base DialogView:</p><ul><li>OverlayColor: the background overlay color for our alert (default is white or transparent).</li><li>UseCurrentPageLocation: acording to the plugin documentation this boolean property will define if our alert will be aligned to the window borders or the current page area. In our case we will set it to false.</li><li>IsCanceledOnTouchOutside: this boolean property will simply define if the user can close the alert by touching the area outside it. In our case we will set it to false.</li></ul><p><strong><em>Note</em></strong>: If you set the BorderColor property remember to add a background color to the content of the DialogView, otherwise it will take the BorderColor as content’s BackgroundColor.</p><p>Then this will be the XAML of our alert:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ec117123a6f0a361a55a252264fcabf/href">https://medium.com/media/0ec117123a6f0a361a55a252264fcabf/href</a></iframe><p>And remember to change base type from ContentView to DialogView on the code behind.<br>Also remember to correctly set the DialogNotifier for the action buttons, these are really important in case we are listening the events to know which option the user pick.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ccccf963dc272b5e959d4ee3ec0157f/href">https://medium.com/media/4ccccf963dc272b5e959d4ee3ec0157f/href</a></iframe><p>And by last we need to open the dialog by calling the Dialog.Instance abstraction, but remember this is an async method and we should use the await keyword, so we can use Device.BeginInvokeOnMainThread if we are not inside an async method.<br>The ShowAsync&lt;TDialogView&gt;() method return a Task&lt;bool&gt; that it’s setted through the DialogNotifier.Cancel() and DialogNotifier.Complete() methods and can be used to execute other parts of our code on each response.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc5088f73150c783161e6a4ba98b4152/href">https://medium.com/media/dc5088f73150c783161e6a4ba98b4152/href</a></iframe><p>This is our result on both platforms:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*nml_52uLWpB2-F6PwtdTCA.jpeg" /><figcaption>Our mad designer’s dreams comes true!</figcaption></figure><p>As we tell the designer the goodness of our recently discovered tool, he’s thinking about the next crazy request…</p><p>Since he loves Ryan Reynolds (who doesn’t, right?), now requests a loading that contains an animated face of Reynolds, together with an inspirational quote, so we will fulfill his wishes!</p><p>As we did before, let’s create another ContentView and change the base type to a LoadingView this time, then set the OverlayColor to gray and add our content inside a StackLayout.</p><p>This will be the XAML of our custom loading:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2f8d3bb445f2df4d95364abb85d3ea0/href">https://medium.com/media/b2f8d3bb445f2df4d95364abb85d3ea0/href</a></iframe><p>Change the base type to LoadingView on the code behind, then create the animation in the constructor method and consume the animation with RunPresentationAnimation and RunDismissalAnimation methods provided by the plugin to run and destroy the animation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b158e180452719df9664d06311aa1435/href">https://medium.com/media/b158e180452719df9664d06311aa1435/href</a></iframe><p>Let’s see the final result!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*1ez8wvVVhHkJbzVFayC9Ag.gif" /><figcaption>Our crazy designer and Ryan Reynolds would be very pleased with the result</figcaption></figure><p>Now he decided that we should warn users through toast using next guideline</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*81aha5P2Qu3n1Bcy93P9Kg.jpeg" /><figcaption>More ComicSans ?</figcaption></figure><p>Once again, create a new ContentView and change it base type to ToastView and this time we need to set some properties:</p><ul><li>HorizontalLayoutAlignment: How it will be positioned horizontally. In our case we set it to Fill.</li><li>VerticalLayoutAlignment: Where the toast will be positioned vertically. In our case we set it to End to placed at the bottom of the screen.</li><li>OffsetY: if we place our toast to top or bottom of the screen, we will need to use this property to adjust the position, specially with iOS because it will not respect the SafeArea adjustment. In our case we set it to -35.</li><li>Duration: expressed in milliseconds, this will determine how long our toast will be visible on screen. In our case we set it to 3000.</li></ul><p>This will be the XAML of our toast:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80497b0cb93fd5eb89ff23852ac78226/href">https://medium.com/media/80497b0cb93fd5eb89ff23852ac78226/href</a></iframe><p>Remember to change the base type to ToastView on the code behind. Also remember that you can add animations to it.</p><p>Let’s see the final result!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*m5BTD_da-oc5xSSohjgL0w.jpeg" /><figcaption>A nice custom toast</figcaption></figure><p>Our crazy designer liked the design of the alert popup that much that he wants to use it for every single one that will appears in the application.<br>To perform this task and to anticipate possible future special request from our designer, let’s create a helper class that can be register as singleton, so it will help us to use it both from our views and from our viewmodels.</p><p>Let’s define our interface methods</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e4f3ae6406517e424978a1189ac5c59/href">https://medium.com/media/3e4f3ae6406517e424978a1189ac5c59/href</a></iframe><p>If we break it down:</p><ul><li>A ShowAlert method to display our alerts, with some required parameters and some optional parameters and returns a bool that indicates if alert was cancelled or accepted.</li><li>Two ShowLoading methods, taking advantage of c# inheritance, we defined a method for regular loadings and another that take a parameter to display a message while loading view is visible.</li><li>A simple HideLoading method to hide our loading view.</li><li>A special method ShowLoadingWithProgressAsync to show a progress count when loading, for example if we want to let users know a file download progress. It take a Func&lt;IProgress&lt;double&gt;, Task&gt; as parameter to pass it on to the loading view and a string to show some custom message while loading view is visible.</li><li>DisplayToast will help us to show a simple toast, we pass a message and duration expressed in milliseconds, we define a default duration of 3 seconds.</li></ul><p>And now the implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c81e53fa8bed893ee165866476ca225c/href">https://medium.com/media/c81e53fa8bed893ee165866476ca225c/href</a></iframe><p>First we define the implementation of our singleton for the helper.</p><p>Then let’s take a closer look to the ShowAlert implementation:</p><p>This would be our alert view</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/160f463bfca3397a704020873ecac7fa/href">https://medium.com/media/160f463bfca3397a704020873ecac7fa/href</a></iframe><p>It’s almost the same as our WinMoneyDialogView but we change the texts with some binding: DialogText, AcceptText and CancelText. These names can be whatever we want, but must be the same when creating the view as we can see here:</p><pre>await Dialog.Instance.ShowAsync&lt;DefaultDialogView&gt;(new<br>{<br>    DialogText = dialogText,<br>    AcceptText = acceptText,<br>    CancelText = cancelText<br>});</pre><p>The library will take care of convert those bindings.</p><p>Now, if we take a look to the first ShowLoading implementation, we simply call the default implementation of the library loading and we set a default message.<br>On the second implementation, we call the Show method first and then the SetMessage method with our custom message.<br>HideLoading will simply call the Hide method of the library.</p><p>ShowLoadingWithProgressAsync as same of ShowAlert, will be an async method, we simply pass the func and the message down to the StartAsync method, that take the same Func&lt;IProgress&lt;double&gt;, Task&gt; and the message.</p><p>Finally for the DisplayToast method we need to create a new toast view:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c56c1c75492035d1d46ea565ca1740cf/href">https://medium.com/media/c56c1c75492035d1d46ea565ca1740cf/href</a></iframe><p>As same as ShowAlert we need to pass the binding</p><pre>Toast.Instance.Show&lt;DefaultToastDialogView&gt;(new<br>{<br>    ToastText = toastText,<br>    Duration = duration<br>});</pre><h4>Test time</h4><p>To test our helper implementation we will create a view and viewmodel associated to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7649629dc16df2b5257e59bb99b341ab/href">https://medium.com/media/7649629dc16df2b5257e59bb99b341ab/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d45f8be4b9644b928fe2a5ae8026030/href">https://medium.com/media/6d45f8be4b9644b928fe2a5ae8026030/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1196670ddd148e3c116d144ef4bf2786/href">https://medium.com/media/1196670ddd148e3c116d144ef4bf2786/href</a></iframe><p>We add bindings to our viewmodel and some implementation on code behind to test.</p><ul><li>OpenRegularLoading call our instance of our DialogHelper and will display a loading for 3 seconds.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*4ibrLPI0CSaOW-GOWZk5tA.gif" /><figcaption>A simple loading overlay</figcaption></figure><ul><li>OpenLoadingWithCustomText will take the text from the Entry and show the loading with it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*YEIF-JPKMZVL-Dla0V3A4A.gif" /><figcaption>A loading overlay with custom text</figcaption></figure><ul><li>OpenDialogWithCustomText this was the original request from our designer, we pass on it a custom message and define “Yes”/”No” as options.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*p_FoOpThPsreUVz0-8wWPg.gif" /><figcaption>Our special dialog now supports any text input</figcaption></figure><ul><li>OpenFakeDownloadLoading here we will fake a downloading task to test the progress.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*mkxr0qWQ6Vnr9J86XrIq5Q.gif" /><figcaption>A loading overlay with progress indicator</figcaption></figure><ul><li>OpenRegularToast_Clicked we implement this method on the code behind of our xaml view to test if our dialog helper works there too. We pass it some text and the duration</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*cD5EYClxB6vhPx5mFJypbQ.gif" /><figcaption>A regular toast displayed on the center of the screen</figcaption></figure><h4>That’s all folks</h4><p>I think this is a really useful library and highly recommend you to try it and if you like it, leave a star on the repo because Kamu (the creator) really deserve it.</p><p>Also you can see my complete sample repository for this post on GitHub.</p><p><a href="https://github.com/FabriBertani/AiFormsDialogsXamarinForms">FabriBertani/AiFormsDialogsXamarinForms</a></p><p>Thanks for reading and keep coding while Vincent Connare laughs from hell 😁</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60dc93903847" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create a custom keyboard with Xamarin Forms (Android)]]></title>
            <link>https://medium.com/swlh/how-to-create-a-custom-keyboard-with-xamarin-forms-android-4fa3b83dad1d?source=rss-e6e92e172a08------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fa3b83dad1d</guid>
            <category><![CDATA[keyboard]]></category>
            <category><![CDATA[xamarin-forms]]></category>
            <category><![CDATA[custom-keyboard]]></category>
            <category><![CDATA[custom]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Fabricio Bertani]]></dc:creator>
            <pubDate>Mon, 13 May 2019 15:06:56 GMT</pubDate>
            <atom:updated>2020-12-08T23:57:23.457Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7iBZmrkKcpTn8sLoXGLY6g.jpeg" /></figure><p>If you prefer to read this article in Spanish, please follow this <a href="https://medium.com/@fabricio.bertani/c%C3%B3mo-crear-un-teclado-custom-con-xamarin-forms-android-dc9fd8bdd2cd">Link</a></p><p>Some time ago a client requested a special keyboard for his application, which had to have certain conditions that the regular Android keyboard didn’t meet.</p><h3><strong>Researching</strong></h3><p>The first option that came to mind was to add a disabled Entry with a GestureRecognizer that displays a control with an animation to emulate the appearance of the keyboard, but quickly discard the idea as it wasn’t reusable.<br>The best option was taking the native path, so I spent quite time researching, but I only found solutions that leads to create a keyboard as a service. I knew that our client wouldn’t like the idea of having to download a separate keyboard to only use it in the application and I needed a solution that should work with Xamarin Forms!<br>As I had to think about its implementation in Xamarin Forms I decided that the best option was to try with a <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/">Custom Renderer</a> of the Entry control since it uses <em>EditText</em> as base for the native control and try to apply all those solutions that I had read previously in it.<br>Luckly I wasn’t alone on this task and I had help from <a href="https://medium.com/u/138f966d53da">Nico Milcoff</a> and <a href="https://medium.com/u/24aaddb3fbe7">Federico Maccaroni</a>, thank you guys!</p><h3>Let’s get down to work!</h3><p><strong>Note: </strong>in order to correctly implement the custom keyboard we are going to need that the Xamarin Forms version to be 3.6.0.135200-pre1 or higher because we need the <a href="https://github.com/xamarin/Xamarin.Forms/blob/release-3.6.0-rc1/Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs#L113">OnFocusChangeRequest</a> method which is only available from this version.</p><p>First we’re going to create the custom control, which will have the next bindable property:</p><ul><li>EnterCommand: typeof ICommand, to bind <em>Enter k</em>ey press action.</li></ul><p>This is how our custom control will be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cac7938cd8c79af146c0d4e2deb1f58/href">https://medium.com/media/3cac7938cd8c79af146c0d4e2deb1f58/href</a></iframe><p>Now we’re moving to our Android project and keep working there (later we will return to our Xamarin Forms project).<br>Before we go on, ensure to have all the required Android packages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*IxuJW3X6d347SfjvuDhtgQ.jpeg" /></figure><p>Next we’re going to edit our Android MainActivity to avoid that native keyboard to show up, for that we will use the SoftInputMode.StateAlwaysHidden attribute</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad029fa97063244e0d0dea1abd799d49/href">https://medium.com/media/ad029fa97063244e0d0dea1abd799d49/href</a></iframe><p>What are we going to do next is start to define our custom keyboard.<br>Inside the <em>Resource/layout</em> folder we are going to create an Android layout named CustomKeyboard typeof <em>InputMethodService.Keyboard</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b75d0bf5c7e7d89e7f252fdecd844486/href">https://medium.com/media/b75d0bf5c7e7d89e7f252fdecd844486/href</a></iframe><p>Firstly we set the alignParentBottom property to <em>true</em> because we want our keyboard to be visible from the bottom side of the screen.<br>Secondly we set the keyPreviewLayout<em> </em>property to <em>null</em> because on this sample we don’t want a response layout when some key is pressed.<br>As you can see in the keyBackground property refers to a drawable called <em>keyboard_background</em>, which doesn’t exist yet, so we are going to create it inside the Drawable folder as an xml file, there we are going to define a state selector for the two states our keys can have: <em>normal</em> (without pressing) and <em>pressed</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/395108e9b0425e6aec698e2d0fd1c170/href">https://medium.com/media/395108e9b0425e6aec698e2d0fd1c170/href</a></iframe><p>As you can see, we are going to have to create another two xml inside the Drawable folder, in which we are going to define the <em>look and feel</em> of our keyboard to match (or not) with our application theme.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f48431c71436e84a22d520d9cad91df/href">https://medium.com/media/4f48431c71436e84a22d520d9cad91df/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49b211e273b4dd4046b3dea3a6d1ba24/href">https://medium.com/media/49b211e273b4dd4046b3dea3a6d1ba24/href</a></iframe><p>Now within the <em>values</em> folder we will create an xml named <strong>ids</strong> which we will need later.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/121f3df4578236993c46fdd9830b06b9/href">https://medium.com/media/121f3df4578236993c46fdd9830b06b9/href</a></iframe><p>Next, inside the <em>Resources</em> folder we will create a new folder called <em>xml</em>. Within it we will create an xml in which we will define the keys of our special keyboard.<br>In our case our keyboard will be called <em>special_keyboard</em>, it will be typeof Keyboard in which we will define the horizontal and vertical size of our keys, the horizontalGap and verticalGap properties refer to the spacing and dimension type %p(in case you’ve never seen it) is a kind of percentage relative to the parent view.<br>Each row of keys will be included within sections delimited by the &lt;Row&gt;&lt;/Row&gt; tags.<br>Our first row will be occupied with a separating line to mark the limit of our keyboard. The Row tag will have a height of 4dp and we will indicate that it is at the top of our keyboard through the rowEdgeFlags property. Then we will add a line as a Key within the <em>Row</em> tags that it would take the full width of the keyboard. Our separator is just another xml that we will create inside the Drawable folder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b49490c310a5f4a1b521227cd3f2043/href">https://medium.com/media/1b49490c310a5f4a1b521227cd3f2043/href</a></iframe><p>Each <em>Key</em> will have two strictly necessary properties: <strong>codes</strong> and <strong>keyLabel</strong><strong><em><br></em>code</strong> will be a number that tells the OS what letter or symbol the key corresponds to. <strong>At this point I want to clarify something:</strong> I found dozens of samples about creating customs keyboards for Android and they have used many different codes to refer to a certain symbol or key. The best list of codes that has been fulfilled most of all that I have tried is the following: <a href="http://www.temblast.com/ref/akeyscode.htm">Android Keycodes</a>. You can also see the <a href="https://developer.android.com/reference/android/view/KeyEvent">official Android</a> docs or even the <a href="https://developer.xamarin.com/api/type/Android.Views.Keycode/">Xamarin Android</a> but none of them has worked with accuracy.<br><strong>keyLabel</strong> is the string that is going to be shown in our key, it is very important to put this property even if we don’t want to show any text in our key (in that case it would be keyLabel=&quot;&quot;).<br>For style decision, at the beginning and at the end of each row, I add a Key with <em>code</em> equal to 0 (so you don’t have any action), the width also of 0 and a spacing of 2%p, these keys will also carry the <em>keyEdgeFlags</em> property with the left or right values as appropriate.<br>Here our full keyboard:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2744e90cce224fde7ac46e82ab9a2800/href">https://medium.com/media/2744e90cce224fde7ac46e82ab9a2800/href</a></iframe><p>Finally before starting to work in our renderer, we will create another folder within Resources, called <em>anim</em> with an xml that we are going to call slide_in_bottom this will be the animation with which our keyboard will appear on the screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5c21827a08166b4ced361212518e184/href">https://medium.com/media/b5c21827a08166b4ced361212518e184/href</a></iframe><p>Now we will create a new folder on our Android project, named <em>Renderers</em> and there we will create our renderer which we will call EntryWithCustomKeyboardRenderer which will extend from EntryRenderer and implement the interface IOnKeyboardActionListener Also within our custom renderer we will create a private class called NullListener which is going to extend from Java.Lang.Object and implement the interface IOnKeyboardActionListener which we are going to use in our renderer to avoid null exceptions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/580e068206e11b015019bc1b71e7e94e/href">https://medium.com/media/580e068206e11b015019bc1b71e7e94e/href</a></iframe><p>Finally, we return to our Xamarin Forms project and implement our special keyboard.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/917369067a3bcc7c49328500097e86c9/href">https://medium.com/media/917369067a3bcc7c49328500097e86c9/href</a></iframe><p>And in our code behind we implement the EnterCommand that we created previously, for the action that we want to happen when we press the <em>Enter</em> key of our custom keyboard.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19737b6649bfbf0c97f0a0d8bacb7641/href">https://medium.com/media/19737b6649bfbf0c97f0a0d8bacb7641/href</a></iframe><p>Here’s the final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*uQOUSV87TkUnp1HLkunf9A.gif" /></figure><p>You can see the complete sample repository on GitHub</p><p><a href="https://github.com/FabriBertani/CustomKeyboardXamarinForms">FabriBertani/CustomKeyboardXamarinForms</a></p><p>In the next post we will see how to make a complex custom keyboard!</p><p>Thanks for reading 😁</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fa3b83dad1d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-create-a-custom-keyboard-with-xamarin-forms-android-4fa3b83dad1d">How to create a custom keyboard with Xamarin Forms (Android)</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cómo crear un teclado custom con Xamarin Forms (Android)]]></title>
            <link>https://medium.com/xamarin-latino/c%C3%B3mo-crear-un-teclado-custom-con-xamarin-forms-android-dc9fd8bdd2cd?source=rss-e6e92e172a08------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc9fd8bdd2cd</guid>
            <category><![CDATA[custom-keyboard]]></category>
            <category><![CDATA[xamarin-forms]]></category>
            <category><![CDATA[custom]]></category>
            <category><![CDATA[keyboard]]></category>
            <category><![CDATA[spanish]]></category>
            <dc:creator><![CDATA[Fabricio Bertani]]></dc:creator>
            <pubDate>Mon, 13 May 2019 15:06:03 GMT</pubDate>
            <atom:updated>2020-12-08T23:59:12.236Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vGp-Oi_Wfd--A_3y0bfkhA.jpeg" /></figure><p>If you prefer to read this article in English, please follow this <a href="https://medium.com/@fabricio.bertani/how-to-create-a-custom-keyboard-with-xamarin-forms-android-4fa3b83dad1d">Link</a></p><p>Tiempo atrás un cliente solicitó un teclado especial para su aplicación, el cual debía tener ciertas condiciones que el teclado regular de Android no cumplía.</p><h3><strong>Investigando un poco</strong></h3><p>La primera opción que se me vino a la mente fue agregar un Entry deshabilitado con un GestureRecognizer que despliegue un control con una animación para emular la aparición del teclado, pero rápidamente descarte la idea por no ser fácilmente reutilizable.<br>Lo mejor era ir por el camino nativo, por lo que estuve bastante tiempo navegando encontrando soluciones que apuntaban a crear un un teclado como servicio, pero al cliente no le iba a agradar la idea de tener que descargar un teclado aparte para usarlo solamente en la aplicación ¡y encima necesitaba una solución que debía funcionar en Xamarin Forms!.<br>Como debía pensar en su implementación en Xamarin Forms decidí que lo mejor era probar hacer un <a href="https://docs.microsoft.com/es-es/xamarin/xamarin-forms/app-fundamentals/custom-renderer/">Custom Renderer</a> del control Entry dado que de base este utiliza <em>EditText</em> como control nativo, e intentar aplicar todas esas soluciones que había leido previamente en el mismo.<br>Por suerte en esta tarea no estuve solo y conté con la gran ayuda de <a href="https://medium.com/u/138f966d53da">Nico Milcoff</a> y <a href="https://medium.com/u/24aaddb3fbe7">Federico Maccaroni,</a> gracias genios!!!</p><h3><strong>Manos a la obra!</strong></h3><p><strong>Nota: </strong>para poder implementar correctamente el teclado custom vamos a necesitar que la versión de Xamarin Forms sea 3.6.0.135200-pre1 o superior porque necesitamos del método <a href="https://github.com/xamarin/Xamarin.Forms/blob/release-3.6.0-rc1/Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs#L113">OnFocusChangeRequest</a> el cual está solo disponible a partir de esta versión.</p><p>Primero vamos a crear el control custom, el cual va a tener la siguiente propiedad bindable:</p><ul><li><em>EnterCommand</em>: del tipo ICommand, para ejecutar una acción al presionar la tecla <em>Enter</em>.</li></ul><p>Asi va a quedar nuestro control custom:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cac7938cd8c79af146c0d4e2deb1f58/href">https://medium.com/media/3cac7938cd8c79af146c0d4e2deb1f58/href</a></iframe><p>A partir de ahora nos vamos a mover al proyecto Android y continuar trabajando desde allí (luego volveremos a nuestro proyecto Forms).<br>Primero nos aseguramos de tener todos los paquetes de Android necesarios:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*zHZAv31f_eqatrizbZGyrw.jpeg" /></figure><p>Lo siguiente que vamos a hacer es editar el MainActivity<em> </em>de Android para asegurarnos (en parte) que el teclado nativo no aparezca, para ello vamos a utilizar el atributo SoftInputMode.StateAlwaysHidden</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad029fa97063244e0d0dea1abd799d49/href">https://medium.com/media/ad029fa97063244e0d0dea1abd799d49/href</a></iframe><p>Lo que vamos a hacer a continuación es empezar a definir nuestro teclado, para eso dentro de la carpeta <em>Resources/layout</em> vamos a crear un layout de Android al que vamos a llamar CustomKeyboard, el mismo va a ser del tipo <em>InputMethodService.Keyboard</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b75d0bf5c7e7d89e7f252fdecd844486/href">https://medium.com/media/b75d0bf5c7e7d89e7f252fdecd844486/href</a></iframe><p>Como primera medida le seteamos la propiedad alignParentBottomen <em>true</em>, porque queremos que sea visible desde la parte inferior de nuestra pantalla.<br>En segundo lugar seteamos la propiedad <em>keyPreviewLayout</em> a <em>null</em> porque para este ejemplo no queremos un layout de respuesta al presionar alguna tecla de nuestro teclado.<br>Como verán en la propiedad keyBackground hace referencia a un drawable llamado <em>keyboard_background</em>, el cual no existe aún, por ende vamos a crearlo dentro de la carpeta Drawable como archivo xml, allí vamos a definir un selector de estado para los dos estados que pueden tener nuestras teclas: <em>normal </em>(sin presionar) y <em>presionadas</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/395108e9b0425e6aec698e2d0fd1c170/href">https://medium.com/media/395108e9b0425e6aec698e2d0fd1c170/href</a></iframe><p>Como vemos vamos a tener que crear otros dos xml dentro de la carpeta Drawable, en los cuales vamos a definir el <em>look and feel </em>de nuestro teclado para tenga concordancia (o no) con nuestra aplicación.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f48431c71436e84a22d520d9cad91df/href">https://medium.com/media/4f48431c71436e84a22d520d9cad91df/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49b211e273b4dd4046b3dea3a6d1ba24/href">https://medium.com/media/49b211e273b4dd4046b3dea3a6d1ba24/href</a></iframe><p>Ahora dentro de la carpeta <em>values </em>crearemos un xml de nombre <strong><em>ids </em></strong>el cual necesitaremos más tarde.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/121f3df4578236993c46fdd9830b06b9/href">https://medium.com/media/121f3df4578236993c46fdd9830b06b9/href</a></iframe><p>A continuación, dentro de la carpeta <em>Resources </em>vamos a crear una nueva carpeta llamada <em>xml</em>. Dentro de la misma vamos a crear un xml en el cual vamos a definir las teclas de nuestro teclado especial.<br>En nuestro caso nuestro teclado se llamara <em>special_keyboard</em>, el mismo sera del tipo Keyboard<em> </em>en el cual le vamos a definir el tamaño horizontal y vertical de nuestras teclas, las propiedades horizontalGap y <em>verticalGap</em> hacen referencia al espaciado y el tipo de dimensión <em>%p</em> (por si nunca lo has visto) es un tipo de porcentaje relativo a la vista padre.<br>Cada fila de teclas van a estar incluidas dentro de secciones delimitadas por el tag &lt;Row&gt;&lt;/Row&gt;<br>Nuestra primera fila la vamos a ocupar con una línea separadora para delimitar el límite de nuestro teclado. Al tag Row le vamos a dar una altura de 4dp<em> </em>y le vamos a indicar que se encuentra al top de nuestro teclado mediante la propiedad rowEdgeFlags. Luego vamos a agregar nuestra linea como una <em>Key </em>dentro de los tags <em>Row </em>y le diremos que ocupe todo el ancho del teclado. Nuestra separadora no es mas que otro xml que crearemos dentro de la carpeta <em>Drawable</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b49490c310a5f4a1b521227cd3f2043/href">https://medium.com/media/1b49490c310a5f4a1b521227cd3f2043/href</a></iframe><p>Cada <em>Key</em> va a tener dos propiedades estrictamente necesarias: <strong><em>codes</em></strong><em> </em>y <strong><em>keyLabel</em></strong>.<br>El <strong>code</strong> va a ser un número que le indica al SO a que letra o símbolo corresponde la tecla. <strong>En este punto quiero hacer una aclaración</strong>, he encontrado decenas de ejemplos de teclados customs para Android y en ellos han usado muchos codes distintos para hacer referencia a determinado símbolo o tecla. La mejor lista de códigos que más se ha cumplido de todos los que he probado es la siguiente: <a href="http://www.temblast.com/ref/akeyscode.htm">Android Keycodes</a>. También pueden ver la <a href="https://developer.android.com/reference/android/view/KeyEvent">oficial de Android</a> o inclusive la de <a href="https://developer.xamarin.com/api/type/Android.Views.Keycode/">Xamarin Android</a> pero ninguna de ellas me ha funcionado con exactitud.<br>Y el <strong>keyLabel </strong>es el string que va a ser mostrado en nuestra tecla, es muy importante poner esta propiedad incluso si no queremos mostrar ningún texto en nuestra tecla (en ese caso sería keyLabel=&quot;&quot;). <br>Por una cuestión de estilo, al principio y al final de cada fila le agregue una Key con el <em>code </em>igual a 0 (para que no tenga ninguna acción), el ancho también de 0 y un espaciado de 2%p tambien estas keys van a llevar la propiedad <em>keyEdgeFlags </em>con los valores left o right según corresponda.<br>Aquí nuestro teclado completo:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2744e90cce224fde7ac46e82ab9a2800/href">https://medium.com/media/2744e90cce224fde7ac46e82ab9a2800/href</a></iframe><p>Por último antes de comenzar a trabajar en nuestro renderer, vamos a crear otra carpeta dentro de Resources, llamada <em>anim</em> con xml que vamos a llamar slide_in_bottom este va a ser la animación con la que nuestro teclado va a aparecer en pantalla.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5c21827a08166b4ced361212518e184/href">https://medium.com/media/b5c21827a08166b4ced361212518e184/href</a></iframe><p>Ahora nos volveremos a posicionar a nivel del proyecto de Android y crearemos una nueva carpeta llamada <em>Renderers</em> y allí crearemos nuestro renderer al que llamaremos EntryWithCustomKeyboardRenderer el cual va a extender de EntryRenderer y también va a implementar la interface IOnKeyboardActionListener También dentro de nuestro custom renderer vamos a crear una clase privada llamada NullListener la cual va a exteder de Java.Lang.Object y de la interface IOnKeyboardActionListener la cual vamos a usar en nuestro renderer para evitar excepciones del tipo null.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ac47cf24c38b0d8786180069059c042/href">https://medium.com/media/8ac47cf24c38b0d8786180069059c042/href</a></iframe><p>Finalmente volvemos a nuestro proyecto Xamarin Forms e implementamos nuestro teclado especial.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/917369067a3bcc7c49328500097e86c9/href">https://medium.com/media/917369067a3bcc7c49328500097e86c9/href</a></iframe><p>Y en nuestro code behind implementamos el EnterCommand que creamos previamente, para la acción que queremos que suceda al presionar la tecla <em>Enter d</em>e nuestro teclado custom.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddf779ece25043c0a71e82849c07c6de/href">https://medium.com/media/ddf779ece25043c0a71e82849c07c6de/href</a></iframe><p>El resultado final:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*uQOUSV87TkUnp1HLkunf9A.gif" /></figure><p>Puedes ver el repositorio de ejemplo en GitHub</p><p><a href="https://github.com/FabriBertani/CustomKeyboardXamarinForms">FabriBertani/CustomKeyboardXamarinForms</a></p><p>En el próximo post veremos como hacer un teclado custom complejo!</p><p>Gracias por leer 😁</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc9fd8bdd2cd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xamarin-latino/c%C3%B3mo-crear-un-teclado-custom-con-xamarin-forms-android-dc9fd8bdd2cd">Cómo crear un teclado custom con Xamarin Forms (Android)</a> was originally published in <a href="https://medium.com/xamarin-latino">Xamarin Latino</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>