wibosco/GhostTypewriter

Support for Reverse

CodingAleCR opened this issue ยท 7 comments

Hey, first of all, awesome job on this, it's reaaaaally nice.

Secondly, I was wondering how difficult would it be to add a reverse function that instead of doing the typing it would go backwards.

@CodingAleCR thanks :-)

I think it should be fairly straight forward by starting at "characters - 1" index, looping through to zero and reversing the alpha transform that is beingg performed.

I should have some free time over the weekend, I'll have a look into it

Hey @CodingAleCR just to clarify when the animation goes in reverse are you wanting the character to be revealed or hidden?

My goal is to simulate erasing a word for example

I should have known better than to write "fairly straight forward" ๐Ÿ˜ฃ.

I've got two PRs: #19 and #20 that both (I believe) add the requested functionality but I'm torn about which approach to go with.

The former (19) makes use of a config to set up the direction and animation type. This config can only be set programmtically so if you use GhostTypewriter exclusively in IB then it will be a bit of a pain to use IB for some setup and code for other setup.

The latter (20) doesn't use a config and instead allows the direction and animation properties to be set directly in IB using IBInspectable. However as IBInspectable doesn't support custom enums, there is a bit of fiddly code to convert from the bool values shown in IB and the enum cases the label uses to control itself - its not bad but it isn't the prettiest. My fear here is that the bool values in IB might not be clear enough and the additional code is a source of potential bugs in the future.

I'd love to hear your thoughts on the PRs (and if they do actually solve your issue)

Thanks a lot for the effort you put into this, I really appreciate it. I know taking the time to do it is sometimes difficult but it's nice that you care about this.

Regarding the PRs... I think, as Apple is moving forward with declarative UIs in Swift UI, #19 would be a better fit going forward in the development of this pod. This way, if you decide to support it fully, you will have a better grounds for this. Also, when I use libraries like this one, I usually just use the IB to set the type of view, but find myself doing the config manually by code. In worst scenarios I've written up wrappers which usually do the trick. Anyway, hope this couple of thoughts help you decide.

So in the end I went for an inbetween solution - dropped the config and just added two seperate properties animationStyle and animationDirection which can be set indepdently of each other and also dropped the IB propeties as they were more confusing than helpful.

These changes should be 2.1.0, let me know if you have any issues.

Works like a charm, thank you!