Regarding the political and social environment precipitating and resulting from Brexit, it's worth considering the research.
This is a study of 50,000 articles about immigration from 2011-2016 in The Guardian, The Telegraph and The Sun. Long story short, it definitely shows a few important points: firstly, all newspapers increasingly concentrated on EU immigrants over their previous focus, which was "illegal" immigrants. Secondly, they transferred their stigmas of "illegal" immigrants over to EU immigrants and Eastern European immigrants in particular, calling on orientalist stereotypes to do so. They also managed to tie EU membership and the Calais crisis together. There are lots of other things in that paper that I could discuss, but for this purpose, that's the meat.
However, evidence that newspapers did this is not quite the same as evidence that this was the critical point in people's minds.
This is a study that looks at how people understood the relationship between Britain and Europe during the critical period. It also found "Eastern vs Western Europe" as a theme, which indicates to me that some of that newspaper work stuck. However, just as importantly, it found three completely different representations in peoples' minds of what constituted the relationship. These representations were strongly linked to geography and social status, meaning that it isn't as straightforward as "immigration=bad". There were even two very different leaver representations: one of "global Britain vs little Europe" that had an internationist bent, and one of "Europe as cultural threat" that was a more nationist concern of having Britishness overwhelmed by Europe.
Finally,
this study considers how remainers have understood Brexit post-referendum. It makes many fascinating points, particularly about the impact of a neoliberal ideology. However, I particularly want to draw out that Remainers were shocked at the fact that there was a large public out there that they had previously
failed to recognise. This has resonance because there is a body of work saying that misrecognition/non-recognition of identity from the powerful to the powerless is a form of political violence that tends to precipitate action. Given that remainers are generally in socially more powerful categories than leavers, this all lends support to the theory (to me at least) that Brexit was -- in some part, at least -- a political kick by the masses against those with higher levels of social and cultural capital. To this end, it was nothing to do with racism or immigration or even anti-EU sentiment at all; just a chance to scream into the void.
(ETA: I note that the latter two papers are not claiming that their study populations are
representative of the public at large, just that they can draw
illustrative representations from the interviews with the study participants. I'm being as careful as I can to make sure this doesn't affect what I'm saying above)