Rotational transformation in CSS not displaying in Webkit / iPhone browsers, yet functioning properly in Chrome Devtools device toolbar

tl;dr: My CSS transform rotate is not rendering on Webkit / iPhone, but it works in Chrome Devtools device toolbar.

Update: I've also opened a separate GitHub issue that is more concise and easier to read, without code excerpts, here.


Giving some context: I'm fetching images and their orientations from my Express API in React. The orientations are mapped to values (0, 180, 270 degrees), then I use CSS to rotate them after the initial render. I lazy-load images while scrolling down using IntersectionObserver API with polyfill for WebKit/Safari included. Works fine in Google Chrome without polyfill and Safari with polyfill, but not rotating images in Chrome/Safari on iPhone.

Here's the relevant code snippet:

// LazyImage.js
render() {
    const { className } = this.props;
    const transformRotationValue = `rotate(${360 - this.state.orientation}deg)`;
    const styles = {
      '-webkit-transform':  transformRotationValue,
      '-moz-transform':     transformRotationValue,
      '-ms-transform':      transformRotationValue,
      '-o-transform':       transformRotationValue,
      transform:            transformRotationValue,
      height:               '500px',
    }
    return (
      <Fragment>
        <p>
          Date: {this.state.date}
        </p>
        <img alt={this.state.date} className={className} style={styles} ref={el => this.element = el} />
      </Fragment>
    );
  }

My CSS code:

/* PhotoFeed.css */
:local(.photos) {
  width: inherit;
  flex-shrink: 0;
  min-height: 100%
}
:local(.photoContainer) {
  height: 500px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  margin-top: 2px;
}

React Component code:

// PhotoFeed.js
return (
              <div className={styles.photoContainer} key={idx}>
                <LazyImage className={styles.photos} src={`${apiRootURL}/photos/demo/${fileName}?token=${Authentication.getToken()}`}/>
              </div>
            );

You can find the full code for both server-side and client-side. The demo code is live at this website.

Tried suggestions from Stack Overflow post, but CSS still not working on iPhone browsers despite working on macOS Chrome/Safari.


Some Updates

UPDATE 1:

Tried another suggestion from comments, but didn't work as expected. Class updates in HTML but CSS doesn't apply properly.


Update 2:

Fixed warnings about unsupported style properties in Chrome DevTools, but images still not rotating on iPhone browsers.

Answer №1

The main challenge arose from pinpointing the issue at hand. It was a classic face-palm moment: the realization that mobile browsers like Chrome and Safari on the iPhone automatically adjust jpeg images to the correct orientation, whereas desktop browsers do not. Once this dawned on me, finding a solution took no longer than 5 minutes. I delved into this informative MDN page and referenced this handy tutorial on using Safari development tools to inspect the user agent string on an iPhone. Armed with this knowledge, I devised a straightforward fix for my rendering method:

render() {
    let { className } = this.props;
    const styles = {
      transform: 'rotate(0deg)',
      height: '500px',
    }
    if (navigator.userAgent.indexOf('iPhone') === -1) {
      styles.transform = `rotate(${360 - this.state.orientation}deg)`;
    }
    return (
      <Fragment>
        <p>
          Date: {this.state.date}
        </p>
        <img alt={this.state.date} className={className} style={styles} ref={el => this.element = el} />
      </Fragment>
    );
  }

Answer №2

In essence, the solution is as follows:

Ensure that you establish the default property as well: rotate(0deg)

Failing to do so may result in functionality errors on iOS and Edge browsers, even though it might work fine on Chrome

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The AudioPlayer refuses to play following a track change

I am looking to implement an audio player in React Nextjs that features interactive dots, each representing an audio track. The functionality I want is such that clicking on a dot will pause the currently playing track (if any) and start playing the select ...

Lending a hand in deselecting a rule within the jcf-hidden add-on using Selenium

Currently, I am working on automating a website that utilizes the jcf-hidden class (a form of jQuery class) which hides the select element I want to access. By removing the display: block !important; property, I was able to successfully interact with the ...

Creating custom project structures with Sails.js 0.10 generators

When looking at the upcoming Sails.js 0.10 release, one exciting feature that stands out is the addition of custom generators (currently @ rc4). You can find a migration guide on Sails' GitHub page highlighting the benefits of these generators, but i ...

When tapping on grid items in the Safari browser using React Material-UI, they mysteriously switch positions

I've encountered an issue with grid Items in my React MATERIAL-UI project, specifically in the Safari browser. The problem does not occur in Chrome or Firefox. Within the grid, there are checkboxes that move from one place to another when clicked, a ...

Understanding Joi validation - setting a field as optional depending on the input received

I have been struggling to integrate the following joi validation. joiSchema = Joi.object().keys({ taskno: Joi.string().alphanum().required().uppercase().trim(), taskstatus: Joi.valid('G', 'C', 'I', 'S'), ...

Automated submission feature for Angular scanning technology

As a newcomer to angular.js, I am dedicated to learning the ins and outs of the framework. Recently, I created a form that enables me to search using a barcode scanner, followed by pressing a submit button. However, I find this process redundant as I wou ...

Is it a problem with Cucumber Js callbacks or a feature issue?

I would like to create a scenario similar to this: Scenario: initialize new Singleton When an unmatched identity is received for the first time Then create a new tin record And establish a new bronze record And generate a new gold record This s ...

When an HTML table utilizes both rowspan and colspan attributes, it may encounter issues with being overlapped by the

I'm working on a straightforward table that showcases the properties of a data element. Each row will represent an element from the AJAX response in a list format. The table is designed with "rowspan" and "colspan" to expand specific cells. However, ...

Invoke an Angular service from a separate JavaScript file

I have a few javascript and html files: User.js, index.html, Door.js I am looking to utilize a function in the User.js file. Link to my user.js file Link to my door.js file I am trying to call the getUserInfo function from User.Js within the Door.j ...

aligning radio buttons and labels on the same horizontal axis

Is there a way to ensure that radio buttons and their labels appear in the same line? I've tried adding margin and padding properties to the span tag, but it doesn't seem to work. Any suggestions on how to solve this issue? <form class="navba ...

What is the method for creating five columns in a single row using Bootstrap?

How can I make my columns responsive for all screen sizes? Currently, I have set the width to 20% for each column, but I would like it to adjust accordingly. Here is a link to the fiddle. Any help on making the row responsive with five columns would be gre ...

I am currently working on coding a function that will search an array to determine if a specific item is present. If the item is found, a variable will be set to true;

So, I have this array of prices for various items like bread, apple, noodles, beef, milk, and coke. const prices = [ ["bread", 20], ["apple", 50], ["noodles", 100], ["beef", 40], ["milk", 32], ["coke", 25], ]; And here's the JavaScript co ...

Jest - verifying the invocation of local storage within an async function that is currently being mocked

I need assistance with testing an API call within a React component. The current setup involves setting localStorage in the api call, which is causing issues when trying to test if it's being called correctly. login = () => { // <--- If I se ...

What is the most effective way to transfer visitor hits information from an Express.js server to Next.js?

I've developed a basic next.js application with an express.js backend. What I'm aiming for is to have the server track hits every time a user visits the site and then send this hit count back to the next.js application. Check out my server.js cod ...

What is the best way to transmit data to a PHP script using AJAX?

I'm facing an issue with my basic ajax script not running. The code I have should work fine. The ajax script is: <html> <head><title>Testing ajax</title> <script type="text/javascript"> function ajax() { ...

React: Struggling to render values within {} of a multidimensional object

I'm facing a challenge that I can't seem to overcome and haven't found a solution for. The values between curly braces are not displaying in the Content and Total components. I've double-checked the JSX rules, but it seems like I might ...

CSS based on conditions for 2 specific divs

Hello, I am working on an HTML page where I need to apply CSS only if certain conditions are met. The div with the id "flipbook-page3-front" will always be present on this HTML page. Sometimes, another div with the id "pagesFlipbook" may also appear on t ...

Press the button to automatically scroll to a designated div section

One of the challenges I'm facing involves a fixed menu and content box (div) on a webpage. Whenever I click on the menu, the content box should scroll to a specific div. Initially, everything was working fine. Here is a sample of it in action: http ...

The code for the `on Submit` function in react-hook-form does not seem to be working as expected

When my form is submitted successfully, I expect the onSubmit function to be triggered. Although the validation is working as expected, the onSubmit function is not getting executed and there are no error messages to indicate what the problem might be. T ...

Error: The command "SET" was not found in the `npm start` script

I encountered an issue while trying to run a React project. After running the command: npm start, I received the following error: sh: SET: command not found npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn npm ERR! &l ...