My favorite was the super useful area label line chart of sales over time. I mean if I was using a screen reader, I'm not sure that I would be glad with this description because it doesn't actually help me understand how my sales are going.
Even when the charts were just instances of the same component using our in-house components that were built, because the API looked something like this, as you can see we have to pass a lot of different props to make a chart look a specific way and these props had to be repeated for each instance of the chart. So it was very easy for a developer to, for example, say that the horizontal margin was 30 instead of 20 and there you have it, the charts now do not look the same.
So to solve all of those problems we started creating a collection of React components that not only had the same visual styles, but had a special focus on things that are very important for us. Like motion design, for example, because we believe that through animation we can guide the eye of a user and help them better understand the dataset, reducing the cognitive overload. We also have a special focus on accessibility. For example, by allowing our users to highlight a specific data series in a chart while we We help users that have color vision deficiencies make the connection in terms of what that specific bar series means, without having to rely on colors. So we can understand that those bars that are highlighted are the bars representing dinner, for example, even though we cannot differentiate purple from pink. We also have a focus on implementing accessibility for screen readers. This line chart, for example, we use area rows in the SVG markup so that a screen reader can actually access the data points that power the line chart and interact with it as if it was a label. So you can see that I'm here navigating on the row of April 2nd, and we can navigate the different cells through rows and columns like we would do if we were interacting with a plain HTML table.
And, of course, Shopify has many different brands that use different visual styles. As I mentioned before, we plan to open source the library soon, so we wanted the library to be flexible enough that people could implement their own visual identity to the charts, but also, we wanted to keep things consistent for whoever was using our charts. So no props need to be passed to each of these components. We have a centralized place where you can define the theme that you want to use and it gets automatically applied to all instances of a chart in your application. We will talk a little bit more to explore more in depth how that works a little later on.
So, in January 2020, Shopify announced that React Native was the future. And since then we have been focusing on writing our mobile apps with React Native and all of our new features with React Native. For our team, this was a very nice opportunity to get the things that we had learned while we were building Polaris Viz for Web and understand how we could create very good experiences for mobile with React Native. The first thing that we thought was, okay, so we can just create a brand new library, call it Polaris Viz Native, and that's it. That was a lot of work, though. We had been working on Polaris Viz for a few years at that point to get the library where it was, and starting from scratch we couldn't reuse all of those things, right? So what if we could extract the platform-specific code, the platform-agnostic code from Polaris Viz for web into a third library, Polaris Viz core, and then react native, the version of Polaris Viz for web and the version of Polaris Viz for React Native could both have Polaris Viz core as a dependency? What exactly could we share? So let's talk a little bit about the similarities and differences between React and React Native.
In React Native, we create components by using HTML tags. Like divs and p's for paragraphs, for example. On React Native, on the other hand, we have to import the markup from the React Native library. So this means that we have, for example, views instead of divs, and text instead of p. Because we're still in Reacts land, we can use all of the common React functionalities like hooks, for example. You can see that I'm using the useState hook exactly the same way, both in web and React Native. There are some differences in terms of how we attach events to the markup, like you can see here on the HTML button, I'm passing the setCount to OnClick, and the Native button, I'm passing it to OnPress.
Comments