Riding without hands (and to a lesser extent one hand) take a few things

Core strength - you really don't steer a bike with your hands/handlebars, you steer it with your legs and core.

The ability to relax - if you let go with one hand and take a death grip on the handlebars with the other you will be very shaky. Relax your body, relax your arms, relax your hands. You will actually be in more control and it will be less tiring for your upper body.

No loose parts! - if your headset on your bike is loose or sloppy the front wheel will want to move around when you let go - not too conducive for riding no handed and sure to induce nerves.. Cable housing that are pulled a bit tight or too short could pull the handlebars to one side or the other too.

Correct bike geometry - some bikes have a twitchy front end. I can ride no handed no problem on my road bike, but not on my TT bike. It's just not the right geometry to do it on. I can however still let go with one hand and drink, signal, etc.

Remember your bike even without you on it really wants to stay upright as long as its moving forward. Keep moving forward and the tendency for your front wheel will be to stay upright and straight. You can test this out by grabbing your bike and walking it by only touching the saddle - like riding no handed without any chance of falling down...