Simple share button. But not that simple.

Recently I had inqusite encounter with a task to try experementaly use Web Share API. This is a cool feature that can invoke your device internal sharing mechanizms. In nutshell, it would open Android or iOS native share menu. In fact it works with a few more devices/browsers, you can check it out here.

Here is a simple example that could help you use it.
Note that when you want to invoke this API you should invoke it using some user events (user should invoke it manuall i.e. press a button). Otherwise it wouldn’t work and display an error that the request is not permitted/blocked by user.
You can use these user activation events:
* change
* click
* contextmenu
* dblclick
* mouseup
* pointerup
* reset
* submit
* touchend

So, just put a button where you need it:

<button class="test-share">Share</button>

And then on example with jQuery, you could do it this way:

$('.test-share').off().on("click", async function() {
    var obj = {
        "title": "test",
        "url": window.location.href,
        "text": "Text you want to display along with shared link"
    }
    try { 
        await window.navigator.share(obj);
    } catch(err) {
        console.log(err);
    }
});

Actually, the part with window.navigator.share(obj) would be the same no matter what you use (TS, Dart, pure JS) as you basically need to work with native JS here.

After you implement it, pressing on the “share” button will open the native share menu of your device.

Please, do check whether this API is available for the device it would be used on. E.g. hide this button if there is no share function available: if (typeof window.navigator.share !== "function") { // hide button }.

Cheers!

Check file newline characters

Sometimes you definitely can face issue with newline characters in your project, some configuration files in the system, or elsewhere. The point is that we don’t bear this stuff in the mind all the time and sometimes just can omit obvious solution. Mostly we don’t even check what newline characters in our files are. But there are cases when these characters might be a root cause of some bug.

I faced the same issue the other day and would like to share the solution.
Continue reading “Check file newline characters”

TDD or no TDD? That’s the question.

Your project is going to be a big mess and every new functionality is hard to implement? You don’t remember or don’t know how this mass of code works? If you ask these questions sometimes you better take a look at this article.

I believe you’ve heard of the TDD. It’s a methodology that gives you a lot of advantages if used correctly. In this article, I’m going to share my experience with TDD, reasons to use TDD, examples, and more.

Continue reading “TDD or no TDD? That’s the question.”

Why should we use services like StackOverflow?

There are a lot of services like Stack Overflow, Quora, and so on. I’m pretty sure you did hear about one at least. Probably you use these services to ask for some help, do you? Anyway, my point isn’t about using these services to get some kind of answers. I’m talking about writing answers by yourself. No, I know that reading existing answers and questions is absolutely helpful practice. But also you should give as many answers as you can.
Continue reading “Why should we use services like StackOverflow?”