Skip to content

Hot preview

zhenglibao edited this page Mar 21, 2024 · 7 revisions

由于苹果审核问题,最新版默认将不接入在线预览功能,想使用的话需要独立接入,如 pod 'FlexLib/preview'

setup environment

  • call FlexRestorePreviewSetting when app start.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    FlexRestorePreviewSetting();
    
    // any other initiation ...
    return YES;   
}

This function will do nothing for product version.

  • start HTTP Server on your mac.

Enter your project directory in terminal, then

python -m SimpleHTTPServer 8000              #for python 2.x
python -m http.server 8000                   #for python 3.x
  • set preview base url

Open preview setting page, you can use one of the following ways:

  1. press Command+D when any sub class of FlexBaseVC appear. This is simplest way but only available in DEBUG mode.
  2. call FlexSetPreviewVC::presentInVC in your app to open this page.

Then you can set the preview base url.

Preview your modification for xml layout

There are three ways to do it:

  1. press Control+E when sub class of FlexBaseVC appear. This will open 'Online Flex Explorer', then you can navigate and view your xml layout by HTTP Protocol. You can also call FlexHttpVC::presentInVC to make it available.

  2. press Command+R when your view controller appears. This will reload your view controller layout but not call your any initiation methods like viewDidLoad.

  3. In preview setting page, turn on 'Online load resource'. Then all the layout will be loaded by HTTP Protocol. You can reopen the current page to refresh it. This will works well even your page need some network request.

Notice: All the shortcuts should be pressed on simulator when view controller is shown, not in XCode. The best way is method 1 and method 3. The method 2 has many limitations.

About directory index

On the preview setting page, you can create directory index. This will traverse all the folders to extract the xml layouts. After this, the framework can easily find the layout by name. Otherwise, the framework will load the layout from the preview base url + 'flexname.xml'.

推荐网友开发的支持热重载xml界面布局的开源库,

https://github.com/zhouxing5311/FlexHotReload

Clone this wiki locally