r/reactnative • • Jan 31 '20

Released my first react-native app!

319 Upvotes

35 comments sorted by

View all comments

3

u/tech-god Jan 31 '20

I have no idea how you coded together the drag and drop math UI, and the business logic to make sure the algebra is always correct. Mind boggling. Could you offer any direction on how one would go about making this?

4

u/TheLartians Jan 31 '20 edited Jan 31 '20

heh, I'll try to boil down the logic as good as I can. I built most components (besides the react part) from scratch in order to have the highest amount control and to learn a lot while doing so too.

The core of the project is a small computer algebra system that I wrote specifically for term manipulation which is able to generate human-readable step-by-step solutions. These solutions are needed to rate user solutions and display the guide. Writing that is a whole story of it's own but it boils down to commutative-associative pattern matching and a lot of unit testing.

Once the algebra system was working, I needed to write a representation for the expressions that can be rendered and manipulated in real time. I chose a tree representation where the individual nodes can have individual purposes. For example some nodes have affine transformations associated with them, others can be rendered. By stringing them together and writing a custom renderer and gesture recogniser we can build a representation of an expression that can be rendered and manipulated with drag and drop gestures. Text is rendered through signed distance fields to be sharp at every scale and resolution.

Once a gesture is detected (e.g. drop x on -x inside a sum) I use the algebra system to find a valid possible transformation. The result of the transformation is then used to rebuild the expression tree. That way I can ensure the algebra to stay correct in every step.

I hope this helps you get an idea. I'd say the most important aspects are patience, passion and willingness to learn and experiment a lot to manage such a project.