169 lines
5.7 KiB
Objective-C
169 lines
5.7 KiB
Objective-C
//
|
|
// WRPageView.h
|
|
// WeRead (读书)
|
|
//
|
|
// Reverse-engineered header reconstruction.
|
|
// The page rendering view. Inherits UIView. Uses CoreText direct drawing
|
|
// via drawRect: — does NOT use UILabel or UITextView for body text.
|
|
// Handles text selection via CoreText hit testing.
|
|
//
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
@class WRActivityIndicator;
|
|
@class WRLoadingProgressView;
|
|
@class WRFriendReviewsButton;
|
|
@class WRCoreTextLayoutFrame;
|
|
@class WRChapterData;
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
// ============================================================================
|
|
#pragma mark - WRPageViewDelegate
|
|
// ============================================================================
|
|
|
|
@protocol WRPageViewDelegate <NSObject>
|
|
@optional
|
|
|
|
/// Called when the user taps a link or internal reference.
|
|
- (void)pageView:(WRPageView *)pageView didTapLinkWithURL:(NSURL *)url;
|
|
|
|
/// Called when the user long-presses to initiate text selection.
|
|
- (void)pageView:(WRPageView *)pageView didBeginSelectionAtPoint:(CGPoint)point;
|
|
|
|
/// Called when text selection changes.
|
|
- (void)pageView:(WRPageView *)pageView selectionDidChangeWithRange:(NSRange)range;
|
|
|
|
/// Called when the user taps the friend reviews button.
|
|
- (void)pageView:(WRPageView *)pageView didTapFriendReviewsWithCount:(NSUInteger)count;
|
|
|
|
/// Called when the page needs to reload its content.
|
|
- (void)pageViewNeedsReload:(WRPageView *)pageView;
|
|
|
|
@end
|
|
|
|
// ============================================================================
|
|
#pragma mark - WRPageView
|
|
// ============================================================================
|
|
|
|
@interface WRPageView : UIView
|
|
|
|
// ---- Delegate ----
|
|
@property (nonatomic, weak, nullable) id<WRPageViewDelegate> delegate;
|
|
|
|
// ---- Content ----
|
|
/// The chapter data driving this page's content.
|
|
@property (nonatomic, strong, nullable) WRChapterData *chapterData;
|
|
|
|
/// The page index within the chapter (0-based).
|
|
@property (nonatomic, assign) NSUInteger pageIndex;
|
|
|
|
/// The layout frame used for CoreText rendering.
|
|
@property (nonatomic, strong, nullable) WRCoreTextLayoutFrame *layoutFrame;
|
|
|
|
// ---- Ivars reconstructed from binary (NSArray, NSMutableArray, etc.) ----
|
|
/// Array of attachment image descriptors (rects, image refs) for inline images.
|
|
@property (nonatomic, strong, nullable) NSArray *imageAttachments;
|
|
|
|
/// Mutable array tracking visible highlight/underline ranges.
|
|
@property (nonatomic, strong, nullable) NSMutableArray *visibleHighlights;
|
|
|
|
/// Timer for auto-read advance.
|
|
@property (nonatomic, strong, nullable) NSTimer *autoReadTimer;
|
|
|
|
/// Timer for loading timeout.
|
|
@property (nonatomic, strong, nullable) NSTimer *loadingTimeoutTimer;
|
|
|
|
/// Current chapter identifier string.
|
|
@property (nonatomic, copy, nullable) NSString *chapterId;
|
|
|
|
// ---- UI Elements (non-text, overlaid on the CoreText layer) ----
|
|
/// Header label showing chapter title or page number.
|
|
@property (nonatomic, strong, nullable) UILabel *headerLabel;
|
|
|
|
/// Background/decorative image view.
|
|
@property (nonatomic, strong, nullable) UIImageView *backgroundImageView;
|
|
|
|
/// Loading activity indicator.
|
|
@property (nonatomic, strong, nullable) WRActivityIndicator *activityIndicator;
|
|
|
|
/// Error / empty-state message label.
|
|
@property (nonatomic, strong, nullable) UILabel *statusLabel;
|
|
|
|
/// Retry button shown on error.
|
|
@property (nonatomic, strong, nullable) QMUIButton *retryButton;
|
|
|
|
/// Share button.
|
|
@property (nonatomic, strong, nullable) QMUIButton *shareButton;
|
|
|
|
/// Loading progress view (thin bar at top or bottom).
|
|
@property (nonatomic, strong, nullable) WRLoadingProgressView *loadingProgressView;
|
|
|
|
/// Bookmark toggle button.
|
|
@property (nonatomic, strong, nullable) QMUIButton *bookmarkButton;
|
|
|
|
/// Font size increase button (toolbar).
|
|
@property (nonatomic, strong, nullable) QMUIButton *fontSizeUpButton;
|
|
|
|
/// Font size decrease button (toolbar).
|
|
@property (nonatomic, strong, nullable) QMUIButton *fontSizeDownButton;
|
|
|
|
/// Friend reviews / notes button.
|
|
@property (nonatomic, strong, nullable) WRFriendReviewsButton *friendReviewsButton;
|
|
|
|
// ---- Selection state ----
|
|
/// Whether the view is currently in text-selection mode.
|
|
@property (nonatomic, assign, readonly) BOOL isSelecting;
|
|
|
|
/// The currently selected string range (NSNotFound if none).
|
|
@property (nonatomic, assign, readonly) NSRange selectedRange;
|
|
|
|
// ---- CoreText Drawing ----
|
|
|
|
/// Main drawing entry point. Draws text and inline images directly into the
|
|
/// CGContext using CoreText. Called by UIKit from -drawRect:.
|
|
- (void)drawInContext:(CGContextRef)context
|
|
withData:(WRChapterData *)chapterData
|
|
size:(CGSize)size
|
|
inRect:(CGRect)rect
|
|
position:(CGPoint)position;
|
|
|
|
// ---- Accessibility ----
|
|
|
|
/// Overridden to provide a plain-text representation of the page content.
|
|
- (nullable NSString *)accessibilityValue;
|
|
|
|
/// Overridden to support VoiceOver page-scroll gestures.
|
|
- (BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction;
|
|
|
|
// ---- Friend Reviews ----
|
|
|
|
/// Updates the friend reviews button with the current count.
|
|
- (void)friendReviewsCount:(NSUInteger)count;
|
|
|
|
// ---- Loading / Error States ----
|
|
|
|
/// Shows the loading indicator and optional progress bar.
|
|
- (void)showLoadingWithProgress:(float)progress;
|
|
|
|
/// Hides loading indicators.
|
|
- (void)hideLoading;
|
|
|
|
/// Shows an error state with a message and retry button.
|
|
- (void)showErrorWithMessage:(NSString *)message;
|
|
|
|
// ---- Text Selection (CoreText hit-testing) ----
|
|
|
|
/// Converts a point in the view to a string index using CTLineGetStringIndexForPosition.
|
|
- (NSInteger)stringIndexForPoint:(CGPoint)point;
|
|
|
|
/// Returns the character range for the line containing the given string index.
|
|
- (NSRange)lineRangeForStringIndex:(NSInteger)index;
|
|
|
|
/// Clears the current selection.
|
|
- (void)clearSelection;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|