Foxconn is a Taiwanese company, operating in China. The Taiwanese businesses knew they were shooting themselves in the foot but opened up factories in China anyways.
The comparison the Ukraine is getting old, mainly because I think a lot of history has been forgotten. Taiwan's formal name is the Republic of China, a government that was in control of Beijing in WWII, and allies with the US. During the Civil War, there was a truce been the CCP and the Kuomingtang (the ruling party of ROC back then) to fight against the Japanese. After WWII, there was a civil war between the CCP and the Kuomingtang. The Kuomingtang lost military engagements and retreated to the island of Taiwan. What makes the issue of Taiwanese and Chinese soveriengty complicated is that the Kuomingtang had asserted territorial rights over mainland China, but the military reality weakens those claims year after year. By the time of the late 80s, that position over reclaiming China had become the equivalent of the right-wing politics in Taiwan.
Culturally, the Taiwanese and Chinese inherit from the same, ancient Chinese civilization, with the Taiwanese having preserved much of the Chinese history, and the PROC did not (Cultural Revolution).
Unlike Ukraine, Taiwan (ROC) is not a buffer state between two major political powers. They were a veto power in the UN before CCP-controlled China, backed by the Soviets, forced their way into the UN Security Council. It is less about Taiwan being protected by US and more about the US honoring old alliances.
It's from that lens that Apple's response is interesting.