The first one is more grammatical. It separates both actions to make it clearer.
The second one is a little bit informal.
You can say "He was driving texting on his phone" people would understand you, but although it isn't correct. It would be more grammaticalbetter to say "He was driving while texting on his phone". It would sound a lot better.