Does the letter i serve as a consonant in words like "onion" and "view"?
Some more words: union, behavior, Daniel.
And the second i in opinion, familiar, brilliant, California.
I am especially concerned with American English.
Contrary to what you learned in school, there are more than just vowels and consonants. In words like 'onion', the i serves as a semi-vowel, or glide. This is represented in IPA as /ˈʌn jən/
and the letter i represents the /j/
sound, which is the same sound as at the start of the word "yes".
Vowels and consonants are not letters, but sounds that are represented by letters. The second ‘i’ in ‘opinion’ represents the sound /j/, which I have seen described as both a palatal glide consonant, and a palatal semi-vowel.