Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timeline lines on iOS devices #2920

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ function stackable_deactivation_cleanup() {
require_once( plugin_dir_path( __FILE__ ) . 'src/block/tabs/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block-components/alignment/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/columns/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/timeline/index.php' );
}

/**
Expand Down
25 changes: 25 additions & 0 deletions src/block/timeline/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* In charge of loading the frontend polyfill for timeline block
* accent color fill for iOS devices
*/

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! function_exists( 'stackable_load_timeline_ios_frontend_polyfill' ) ) {
function stackable_load_timeline_ios_frontend_polyfill( $block_content, $block ) {
// Add class stk-block-timeline__ios-polyfill to $block_content
return preg_replace( '/stk-block-timeline/', 'stk-block-timeline stk-block-timeline__ios-polyfill', $block_content, 1 );
}

$user_agent = ! empty( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
// Add polyfill if device is iPhone/iPad
// Include Safari because by default the User Agent in Safari on iPadOS is same on MacOS
// Reference: https://developer.apple.com/forums/thread/119186
if ( ! empty( $user_agent ) && ( stripos( $user_agent, 'iPhone' ) !== false || stripos( $user_agent, 'iPad' ) !== false || stripos( $user_agent, 'Safari/' ) !== false ) ) {
bfintal marked this conversation as resolved.
Show resolved Hide resolved
add_filter( 'render_block_stackable/timeline', 'stackable_load_timeline_ios_frontend_polyfill', 10, 2 );
}
}
9 changes: 9 additions & 0 deletions src/block/timeline/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
padding: 16px 0;
margin-block-start: 0 !important;
}

// iOS polyfill for timeline accent color
// For tablet and mobile, fill timeline lines with accent color
@include tablet-mobile {
.stk-block-timeline.stk-block-timeline__ios-polyfill {
--fixed-bg: linear-gradient(to bottom, var(--line-accent-bg-color, #000) 0, var(--line-accent-bg-color-2, #000) var(--line-accent-bg-location, 50%));
}
}

// Remove the default bottom margin of the timeline block because it's annoying
// to keep on removing it when you want to stack them. This works in conjunction
// with the stackable.resizable-bottom-margin.default filter in edit.js.
Expand Down
Loading